我正在尝试使用Gmail SMTP发送邮件。代码工作正常。问题是从收到它总是显示我想要显示的个人电子邮件地址no-reply@domain.com
似乎缺少什么?
<?php
require_once "Mail.php";
$from = "No-Reply<no-reply@domain.com>";
$to = "Test Reception <reception@gmail.com>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
$host = "ssl://smtp.gmail.com";
$port = "465";
$username = "example@gmail.com";
$password = "password";
$headers = array (
'From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array (
'host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password)
);
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
?>
答案 0 :(得分:4)
我假设因为GMail知道你是谁(因为你登录了)并且不允许你欺骗发件人。