如何使用 PhpMailer 和 WAMP 发送电子邮件

How to send Email with PhpMailer and WAMP

我不知道还有什么方法可以使用 phpmailer 和 WampServer 发送电子邮件。我已经配置了 WAMP,就像我在很多论坛上看到的那样,但我无法让它工作。我有这个例子:

<?php 
if(isset($_POST['email'])){
    //envia correo desde el servidor local (pruebas)
    include("clases/class.phpmailer.php");
    include("clases/class.smtp.php");
    $mail = new PHPMailer();
    $mail->IsSMTP();
    $mail->SMTPAuth = true;
    $mail->SMTPSecure = "ssl";
    $mail->Host = "smtp.gmail.com";
    $mail->Port = 587;
    $mail->Username = "restofinder2016@gmail.com";
    $mail->Password = "****";

    $mail->From = "restofinder2016@gmail.com";
    $mail->FromName = "Resto";
    $mail->Subject = "Subject del Email";
    $mail->AltBody = "Hola, te doy mi nuevo numero\nxxxx.";
    $mail->MsgHTML("Hola, te doy mi nuevo numero<br><b>xxxx</b>.");
    //$mail->AddAttachment("files/files.zip");
    //$mail->AddAttachment("files/img03.jpg");
    $mail->AddAddress($_POST['email'], "user name");
    $mail->IsHTML(true);

    if(!$mail->Send()) {
        echo "Error: " . $mail->ErrorInfo;
        return false;
    }

    //fin enviar correo usuando servidor local  
}
?>

<form id="form1" name="form1" method="post" action="">
    <p>
        <label for="email"></label>
        <input type="text" name="email" id="email" />
    </p>
    <p>
        <input type="submit" name="enviar" id="enviar" value="Enviar" />
    </p>
</form>

有人告诉我它不适用于 gmail,我应该使用其他类型的邮件。我收到此错误:

SMTP 错误:无法连接到 SMTP 主机。错误:SMTP 错误:无法连接到 SMTP 主机。

我该怎么做才能让它发挥作用?

非常感谢!

试试这个端口

$mail->Port = 465;

我想这会解决你的问题。

确保你有

;extension=php_openssl.dll

在 php.ini

中未注释

并改变

$mail->SMTPSecure = "ssl";

$mail->SMTPSecure = "tls";

因为您正在为 ssl 使用 tls 端口 (https://support.google.com/mail/answer/7126229)

如果他们两个都不帮忙加

$mail->SMTPDebug = 2;

它将向您显示有关该问题的更多详细信息

它对我有用:https://websistent.com/using-sendmail-on-windows/ 只是代替这部分 "smtp_server=ssl://smtp.gmail.com" 我这样设置:"smtp_server=smtp.gmail.com"。