用于从php脚本发送邮件的Gmail和Mac设置?

时间:2015-06-25 07:38:23

标签: php macos email ubuntu-14.04

我想从我的php脚本发送邮件,但无法找到mac和gmail的配置设置。 我的php脚本是:

   $to ="sender email id";
   $subject = "Confirmation";
   $header = "";
   $message = "";
   $sentmail = mail($to,$subject,$message,$header);

   if($sentmail)
   {
      echo "Your Confirmation link Has Been Sent To Your Email Address.<br>";
   }
   else
   {
      echo "Cannot send Confirmation link to your e-mail address<br>";
   }

我还在使用Mail.php在我的ubuntu机器上尝试了另一个代码,但它显示了一些身份验证错误。这是代码:

include_once "Mail-1.2.0/Mail-1.2.0/Mail.php";

$from = '<sender@gmail.com>';
$to = '<receiver@gmail.com>';
$subject = 'Hi!';
$body = "Hi,\n\nHow are you?";

$headers = array(
'From' => $from,
'To' => $to,
'Subject' => $subject
);

$smtp = Mail::factory('smtp', array(
    'host' => 'ssl://smtp.gmail.com',
    'port' => '465',
    'auth' => true,
    'username' => 'sender@gmail.com',
    'password' => 'xxxxx'
 ));



$mail = $smtp->send($to, $headers, $body);

if (PEAR::isError($mail)) {
  echo('<p>' . $mail->getMessage() . '</p>');
} else {
 echo('<p>Message successfully sent!</p>');
}

为我提供一些解决方案,以便我可以从我的php脚本成功发送邮件。

1 个答案:

答案 0 :(得分:0)

尝试将第一个脚本的标题更改为:

$header = 'From: put from email address here' . "\r\n" .
        'Reply-To: put from email address here' . "\r\n" .
        'X-Mailer: PHP/' . phpversion();