更改php pear邮件中的电子邮件标题

时间:2012-03-01 21:15:34

标签: php email smtp pear

我正在试图弄清楚如何使用谷歌的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>");
}

1 个答案:

答案 0 :(得分:1)

您必须设置ssl加密。 Google可以为您提供帮助http://www.google.com/search?q=pear+mail+ssl