0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【PHP】x-server から Gmail含め、メールを送信する。

Posted at

前提条件

送信先:soushin@gmail.com(記載用)
送信元(自分):test_01@xs810378.xsrv.jp(エックスサーバーメール)

ソースコード

mail.php

PHP mail.php

<?php

require(dirname(__FILE__) . '/functions.php');

// メール送信 可変
$MAILTO = "soushin@gmail.com"; // 宛先のメールアドレス

// メール本文
$content = "本文:てすと本文:てすと本文:てすと本文:てすと";

// 送信者
//==========  Gmail用 エンコーディング対策
$senderName = base64_encode(Send_Mail_GOGO::SENDER_NAME);
$senderName = "=?UTF-8?B?{$senderName}?=";

// ヘッダー情報 === test_01@xs810378.xsrv.jp エックスサーバーメール
$mailHeaders = <<< EOF
From: {$senderName} <test_01@xs810378.xsrv.jp>
Reply-To: test_01@xs810378.xsrv.jp
Return-Path: test_01@xs810378.xsrv.jp
X-Mailer: X-Mailer
MIME-Version: 1.0
Content-Type: text/plain;charset=UTF-8
Content-Transfer-Encoding: 8bit
EOF;


// mb_language("ja");
mb_internal_encoding("UTF-8");

// メール送信処理
$result = mb_send_mail($MAILTO, Send_Mail_GOGO::SUBJECT, $content, $mailHeaders);

// メール送信処理結果出力
if ($result) {
    echo "送信成功";
} else {
    echo "送信失敗";
}

・functions.php

php functions.php
//=== メール送信用
class Send_Mail_GOGO
{
    //=== メール件名
    const SUBJECT = "件名:(お問い合わせありがとうございます)";
    //=== メール送信者名
    const SENDER_NAME = "株式会社 xxxぺけぺけ";
}

送信結果

スクリーンショット (655).png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?