简体   繁体   中英

How to send Email with PhpMailer and WAMP

I dont know what else to do to make email sending works using phpmailer and WampServer. I have configured WAMP just as a I read in a lot of forums, but I cant make it work. I have this example:

<?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>

I was told that it doesnt work with gmail, that I should use some other kind of mail. I get this error:

SMTP Error: Could not connect to SMTP host. Error: SMTP Error: Could not connect to SMTP host.

What can I do to make it work?

Thank you very much!

Try this port

$mail->Port = 465;

I think this will solve your problem.

Make sure that you have

;extension=php_openssl.dll

uncommented in php.ini

And change

$mail->SMTPSecure = "ssl";

to

$mail->SMTPSecure = "tls";

as your are using tls port for ssl ( https://support.google.com/mail/answer/7126229 )

If both of them don't help add

$mail->SMTPDebug = 2;

It will show you more details about the problem

它为我的作品: https://websistent.com/using-sendmail-on-windows/就代替这部分的“smtp_server = SSL://smtp.gmail.com”我这样设置的:“smtp_server = smtp.gmail .com”。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM