【问题标题】:PHP mailer smtp setup with gmail使用 gmail 的 PHP 邮件 smtp 设置
【发布时间】:2015-12-03 01:31:27
【问题描述】:

大家好,我已经被这个问题困扰了一段时间了。我正在尝试从 xampp 发送邮件。我已经经历了这里发布的几个解决方案,但似乎没有一个仍然有效。有点需要有人给我指出正确的方向。

所以在我的 php.ini

[mail function]
SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = user@gmail.com
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"

我也有 sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t";

注释

现在在我的 sendmail.ini

[sendmail]

smtp_server=smtp.gmail.com
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
auth_username=user@gmail.com
auth_password=123456
force_sender=shadidhaque2014@gmail.com

P.s: 我在 sendmail.ini 中只有上面的代码 现在对于 php 脚本,我有一些非常简单的东西:

$send=mail('rzs2009@yahoo.com', 'subject', 'blah blah blah');
                    if ($send) {
                        # code..
                        echo "yes";
                    }else
                    {
                        echo "no";
                    }

现在每次我尝试运行该程序时,我都会得到一个不。所以没有电子邮件被发送。我哪里可能出错了。 提前致谢。

【问题讨论】:

  • 检查您定义的邮件日志文件。这就是他们的目的!
  • 你自己打电话给mail()会出错;这是一条糟糕的路。您已将此问题标记为 PHPMailer,但没有使用它。 Get it here,关注this example,和read the docs

标签: php email phpmailer


【解决方案1】:

像这样修改你的代码:

function smtpmailer($to, $from, $from_name, $subject, $body) { 
    global $error;
    $mail = new PHPMailer();  // create a new object
    $mail->IsSMTP(); // enable SMTP
    $mail->SMTPDebug = 0;  // debugging: 1 = errors and messages, 2 = messages only
    $mail->SMTPAuth = true;  // authentication enabled
    $mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
    $mail->Host = 'smtp.gmail.com';
    $mail->Port = 465; 
    $mail->Username = GUSER;  
    $mail->Password = GPWD;           
    $mail->SetFrom($from, $from_name);
    $mail->Subject = $subject;
    $mail->Body = $body;
    $mail->AddAddress($to);
    if(!$mail->Send()) {
        $error = 'Mail error: '.$mail->ErrorInfo; 
        return false;
    } else {
        $error = 'Message sent!';
        return true;
    }
}

http://www.web-development-blog.com/archives/send-e-mail-messages-via-smtp-with-phpmailer-and-gmail/

【讨论】:

  • 请不要链接到过时的文档。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-01-05
  • 2015-01-30
  • 2010-10-22
  • 2015-10-22
  • 1970-01-01
  • 2023-03-05
  • 2010-11-08
相关资源
最近更新 更多