我正在试图弄清楚如何使用谷歌的SMTP服务器从php发送电子邮件,但更改FROM标头以匹配我的域。电子邮件发送正常,但收件人看到它是从myemail@gmail.com发送的,而不是me@mydomain.com。我正在使用php pear邮件发送。
require_once("Mail.php");
$from = "Me <me@mydomain.com>";
$to = "Zach <myemail@gmail.com>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
$host = "smtp.gmail.com";
$username = "****";
$password = "****";
$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password));
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}