【问题标题】:sending mail using php使用php发送邮件
【发布时间】:2012-10-02 16:24:16
【问题描述】:

我在这里看到过类似的问题,但是我无法解决我的问题。 我正在尝试使用 php 发送邮件...但这不起作用。

<?php
$email_from="admin@crorebook.com";
ini_set("sendmail_from", $email_from);
$headers = "From: $email_from";
mail('gitudrebel94@gmail.com','Registration confirmation','Hihihihihihih','$headers');
?>

它在 Windows 服务器上给了我以下错误: “SMTP 服务器响应:550 没有这样的用户”

在 nginx 服务器上出现以下错误:

“服务器遇到内部错误或配置错误,无法完成您的请求。

请联系服务器管理员、网站管理员并告知他们错误发生的时间,以及您可能所做的任何可能导致错误的事情。

服务器错误日志中可能会提供有关此错误的更多信息。

此外,在尝试使用 ErrorDocument 处理请求时遇到 500 Internal Server Error 错误。”

【问题讨论】:

  • 尝试删除'$headers'周围的单引号
  • 你不需要 ini_set 行
  • 删除了 ini_set 行,但没有任何改变

标签: php smtp


【解决方案1】:

您是否设置了发送邮件服务器?如果您在 Windows 中运行,则需要 SMTP 服务器,如果是 linux,则需要 sendmail 或类似配置并在本地运行。

SMTP 错误消息表明它不是一个开放的转发器 - 因为它不会让任何人要求它向其他人/其他地方发送电子邮件......这很好,因为垃圾邮件发送者会如果是,请使用它。它可能需要某种身份验证(您的用户名/密码),然后才能将电子邮件发送给机器本地以外的任何人(如机器上托管的域的电子邮件地址)。

不幸的是,PHP mail() 方法无法处理此问题,因此您需要查看第三方软件包 - PEAR mailPHPMailer 是不错的选择。

使用 PHPMailer 完成任务:

require_once /*lib location*/"phpmailer/class.phpmailer.php";
require_once /*lib location*/"phpmailer/class.smtp.php";

$mail=new PHPMailer();
$mail->IsSMTP();
$mail->Host=/*Your host*/;
$mail->Port=465;//For SSL - use this if you can
$mail->SMTPAuth=true;
$mail->SMTPSecure="ssl";
$mail->SMTPDebug=2;//Comment once it works, but the debug info is invaluable
$mail->Username=/*Your username*/;
$mail->Password=/*Your password*/;
$mail->setFrom("admin@crorebook.com");
$mail->Subject='Registration confirmation';
$mail->Body='Hihihihihihih';
$mail->AddAddress('gitudrebel94@gmail.com');
$mail->Send();

【讨论】:

    猜你喜欢
    • 2018-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-19
    相关资源
    最近更新 更多