php - 邮件程序错误 : The following From address failed: Called Mail() without being connected

标签 php email

我正在使用 PHPMailer 使用 SMTP 发送电子邮件。我已经设置好了一切。

但最后我收到错误:
Mailer Error: The following From address failed: Email Address : Called Mail() without being connected

我知道要设置编码顺序,我也做了,但还是一样的错误。请帮我解决这个问题。

我的代码:

<?php

require 'PHPMailer.php';

error_reporting(E_ALL);
ini_set('display_errors', '1');

$name = $_POST["name"];
$email = $_POST["email"];
$subject = $_POST["subject"];
$message = $_POST["message"];

$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "smtp.live.com";
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = "example@outlook.com";
$mail->Password = "password";
$mail->SMTPSecure = 'tls';

$mail->From = "info@neelcomputech.com";
$mail->FromName = $name;
$mail->AddAddress("info@neelcomputech.com");

$mail->IsHTML(true);

$mail->Subject = $subject;

$mail->Body = $mail_body = "<html> <body>";
$mail_body = "<b>Hello Admin,</b><br><br>You have got email from your website.<br><br>";
$mail_body .= '<table style="" cellpadding="3">';
$mail_body .= "
                <tr>
                <td width='50'> <strong> Name </strong> </td>
                <td width='5'> : </td>
                <td> $name </td>
                </tr>
                <tr>
                <td> <strong> Email </strong> </td>
                <td> : </td>
                <td> $email </td>
                </tr>
                <tr>
                <td> <strong> Message </strong> </td>
                <td> : </td>
                <td> $message </td>
                </tr>
                </table>
                </body> </html>"; 

if(!$mail->Send())
{
    echo 'Mailer Error: ' . $mail->ErrorInfo;
}
else
{
    echo 'success';
}

?>

最佳答案

<?php

    require 'PHPMailer.php';

    error_reporting(E_ALL);
    ini_set('display_errors', '1');

    $name = $_POST["name"];
    $email = $_POST["email"];
    $subject = $_POST["subject"];
    $message = $_POST["message"];

    $mail = new PHPMailer();
    $mail->IsSMTP();
    $mail->Host = "smtp.neelcomputech.com"; // Your SMTP PArameter
    $mail->Port = 587; // Your Outgoing Port
    $mail->SMTPAuth = true; // This Must Be True
    $mail->Username = "info@neelcomputech.com"; // Your Email Address
    $mail->Password = "YOUR PASSWORD"; // Your Password
    $mail->SMTPSecure = 'tls'; // Check Your Server's Connections for TLS or SSL

    $mail->From = "info@neelcomputech.com";
    $mail->FromName = $name;
    $mail->AddAddress("info@neelcomputech.com");

    $mail->IsHTML(true);

    $mail->Subject = $subject;

    $mail->Body = $mail_body = "<html> <body>";
    $mail_body = "<b>Hello Admin,</b><br><br>You have got email from your website.<br><br>";
    $mail_body .= '<table style="" cellpadding="3">';
    $mail_body .= "
                    <tr>
                    <td width='50'> <strong> Name </strong> </td>
                    <td width='5'> : </td>
                    <td> $name </td>
                    </tr>
                    <tr>
                    <td> <strong> Email </strong> </td>
                    <td> : </td>
                    <td> $email </td>
                    </tr>
                    <tr>
                    <td> <strong> Message </strong> </td>
                    <td> : </td>
                    <td> $message </td>
                    </tr>
                    </table>
                    </body> </html>"; 

    if(!$mail->Send())
    {
        echo 'Mailer Error: ' . $mail->ErrorInfo;
    }
    else
    {
        echo 'success';
    }

    ?>

在您的 smtp 身份验证中,您必须使用自己的参数。 您也可以在 PHPMailer 的网站上查看其他邮件服务器的 smtp 参数: phpmailer.worxware.com/index.php?pg=tip_srvrs

关于php - 邮件程序错误 : The following From address failed: Called Mail() without being connected,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23776256/

相关文章:

php - jquery永久改变html

php - 执行 AJAX 请求后未应用 CSS

php - 如何解决 Php date() 错误

html - 在电子邮件中嵌入 HTML 表单

email - MIME 电子邮件的 Base64 解码不起作用(GMail API)

linux - 在 rc.local 中通过管道将 echo 传送到 sendmail 失败

.NET 预定群发邮件开源解决方案

python - 有没有办法获取新的YouTube订阅者的电子邮件? python

php - Codeigniter 中的枚举表行 ID

php - Centos vm 上 Symfony 的权限问题