【问题标题】:Sending mail via PHP function通过 PHP 函数发送邮件
【发布时间】:2019-01-30 16:26:11
【问题描述】:

我正在尝试使用 sendmail(在 /usr/sbin/sendmail 中)从服务器 PLESK 发送简单的电子邮件通过 PHP mail() 函数

我已经阅读了 John Conde 在这里解释的清单PHP mail function doesn't complete sending of e-mail,我的问题很可能与提供商有关,因为我的脚本 将电子邮件发送到 gmail 帐户,但没有其他人;发送到 gmail 帐户的电子邮件进入垃圾邮件文件夹。我正在尝试发送到 name@company.it 例如。

在你问之前,我已经检查了我的发件人 IP 信誉,验证了反向 DNS 结果并在http://mail-tester.com/ [垃圾邮件检查器] 上获得了 9 分(满分 10 分)。

在域的 php.ini 中,我将字段设置为:SMTP、smtp_port、sendmail_from、sendmail_path、auth_password、auth_username。 (因为我在域上有 SSL 证书,所以我在提供商 smtp 服务器上使用 465 端口)。

这是sn-p的代码:

<?php
    error_reporting(-1);
    ini_set('display_errors', 'On');
    ini_set('display_startup_errors', 1);
    set_error_handler("var_dump");

    //
    $replyTo = "website@globalpower.it";
    $mailTo  = "fcaliari@e-globalservice.it";

    //Test sender delle Email
    $headers = 'From: '.$replyTo."\r\n".
               'Reply-To: '.$replyTo."\r\n" .'X-Mailer: PHP/' . phpversion();

    if (mail($mailTo,"Title","Body of the message",$headers)){
       echo "Mail ok";
    } else {
       echo "Error Mail";
    }
?>

这是邮件目录下服务器的日志

Aug 23 10:38:20 webserver check-quota[1905]: Starting the check-quota filter...
Aug 23 10:38:20 webserver journal: plesk sendmail[1904]: handlers_stderr: SKIP
Aug 23 10:38:20 webserver journal: plesk sendmail[1904]: SKIP during call 'check-quota' handler
Aug 23 10:38:20 webserver postfix/pickup[1560]: DAC521A8B: uid=10003 from=<rootgp@globalpower.it>
Aug 23 10:38:20 webserver postfix/cleanup[1910]: DAC521A8B: message-id=<20180823143820.DAC521A8B@webserver.e-globalservice.it>
Aug 23 10:38:20 webserver postfix/qmgr[1561]: DAC521A8B: from=<rootgp@globalpower.it>, size=450, nrcpt=1 (queue active)
Aug 23 10:38:20 webserver postfix-local[1915]: postfix-local: from=rootgp@globalpower.it, to=fcaliari@e-globalservice.it, dirname=/var/qmail/mailnames
Aug 23 10:38:20 webserver postfix-local[1915]: cannot chdir to mailname dir fcaliari: No such file or directory
Aug 23 10:38:20 webserver postfix-local[1915]: Unknown user: fcaliari@e-globalservice.it
Aug 23 10:38:20 webserver postfix/pipe[1914]: DAC521A8B: to=<fcaliari@e-globalservice.it>, relay=plesk_virtual, delay=0.05, delays=0.03/0.01/0/0.01, dsn=2.0.0, status=sent (delivered via plesk_virtual service)
Aug 23 10:38:20 webserver postfix/qmgr[1561]: DAC521A8B: removed

在日志中出现了这封电子邮件 rootgp@gloablpower.it,我从未在 php.ini 文件或脚本中使用过它

任何帮助不胜感激!

【问题讨论】:

  • 你检查过vhost文件(用于ServerAdmin)

标签: php email sendmail spam


【解决方案1】:

php 脚本中发送邮件时,我强烈建议使用SMTP 中继通过专用电子邮件服务器发送电子邮件,而不是直接通过您的网络服务器发送。原因是:如果您托管在共享服务器上,那么同样托管在该服务器上的其他人可能会发送垃圾邮件(这会导致您的电子邮件被标记为垃圾邮件)。

我在使用 PHPMailer 方面有过很好的体验,您可以调整很多设置以使设置与您的环境/设置配合使用。

参考请见:https://github.com/PHPMailer/PHPMailer

【讨论】:

  • 我听到你哈哈哈
  • 在 php.ini 文件中我已经使用了另一个 SMTP 服务器,与我的 Web 服务器不同。我会等待另一个答案,但如果有人不能帮助我,我想我会使用 PHPMailer!
  • 说“用别的东西”不是解决问题的办法。
  • 我不只是说use something else,我说的是我会使用什么以及为什么我会推荐使用它。
猜你喜欢
  • 2014-03-24
  • 1970-01-01
  • 2015-03-27
  • 2013-01-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多