【问题标题】:Mail not being sent with PHP邮件未使用 PHP 发送
【发布时间】:2013-09-26 08:51:51
【问题描述】:

我正在尝试从我的 PHP 应用程序发送邮件。下面是我的代码。

    <?php
    error_reporting  (E_ALL);
    ini_set ('SMTP', 'smtp.live.com');
    ini_set ('smtp_port', '587');
    ini_set ('sendmail_from', 'mymail@hotmail.com');

    $to = "urmail@hotmail.com";
    $subject = "Test mail";
    $message = "Hello! This is a simple email message.";

    $headers = "From:mymail@hotmail.com\r\n";
    $headers .= "X-Mailer: php\r\n";
    $headers .= "Reply-To:mymail@hotmail.com\r\n";
    $headers .= 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    $result = mail($to,$subject,$message,$headers);
    if($result)
    {
   echo "Mail Sent.";
    }
    else
    {
   echo ("error");
    }
   ?>

它给了我“邮件已发送”的消息,所以我希望收到邮件……但没有。假设收到邮件可能会延迟,我现在等了 3 天。还检查了我的垃圾邮件,但什么也没有……所以我相信我的代码没有发送邮件……不知道为什么。

我可能遗漏了一些设置...但由于这是我第一次使用 PHP 邮件,我不知道遗漏了哪些设置。阅读邮件文档后...没有找到任何此类要求/设置。任何帮助将非常感激。

【问题讨论】:

  • 不确定您是否可以从脚本中使用 smtp.live.com,可能他们不会接受您的连接。
  • 你在设置你的hotmail用户名/密码吗?这个问题可能会有所帮助link
  • 希望这个问题现在可以解决。是吗?

标签: php email


【解决方案1】:

如果你不介意使用 PHPMailer 库试试这个:

<?php
    require("PHPMailer_5.2.4/class.phpmailer.php");

    $mail = new PHPMailer();
    $mail->SMTPDebug = true;
    $mail->IsSMTP();  // telling the class to use SMTP
    $mail->SMTPAuth   = true; // SMTP authentication
    $mail->Host       = "StartTLS://smtp.live.com"; // SMTP server
    $mail->Port       = 587; // SMTP Port
    $mail->Username   = "username"; // SMTP account username
    $mail->Password   = "xxx";        // SMTP account password

    $mail->SetFrom('from_emailid', 'yourname'); // FROM
    $mail->AddReplyTo('replyto_emailid', 'name'); // Reply TO

    $mail->AddAddress('recepeint_emailid'); // recipient email

    $mail->Subject    = "First SMTP Message"; // email subject
    $mail->Body       = "Hi! \n\n This is my first e-mail sent through live SMTP using PHPMailer.";

    if(!$mail->Send()) {
      echo 'Message was not sent.';
      echo 'Mailer error: ' . $mail->ErrorInfo;
    } else {
      echo 'Message has been sent.';
    }

【讨论】:

  • 我刚刚尝试并测试了代码,它对我来说运行良好..你能指出你收到的任何具体错误吗?
【解决方案2】:

您不能在不验证自己的情况下使用 smtp.live.com。

【讨论】:

  • 添加了下面的代码 ini_set ('smtp_user', 'mymail@hotmail.com'); ini_set ('smtp_password', 'mypass'); ini_set ('smtp_start_tls', '1');但仍然没有邮件。此外,当我尝试在未验证自己的情况下发送邮件时,它应该不会出错吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-01-05
  • 2013-09-25
  • 1970-01-01
  • 2013-07-18
  • 2014-03-06
  • 2016-02-18
  • 2018-05-08
相关资源
最近更新 更多