简体   繁体   中英

PHPMailer works on local but not on OVH server

I know this question has been asked many times, but I don't find an answer to my problem.

I have the following code:

require 'vendor/autoload.php';
    
use PHPMailer\PHPMailer\PHPMailer;
    
$mail = new PHPMailer();

$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'myEmailAddress@gmail.com';
$mail->Password = 'myPass';
$mail->Port = 587; 

$mail->setFrom('myEmailAddress@gmail.com', 'Name Surname');
$mail->addAddress('myFriend@gmail.com', 'My Friend Mark');

$mail->Subject = 'Test';
$mail->isHTML(true);

$body = "<h1> TEST EMAIL </h1> <p> MY EMAIL IS AWESOME </p>";
$mail->Body = $body;

if($mail->send()){
    echo "SENT!";
}else{
    echo "Error ".$mail->ErrorInfo;
}

This works perfectly on my local server in Windows with XAMPP. When I try to run it on my OVH server I get

SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

Can someone help me?

You cannot use an external SMTP (such as smtp.gmail.com) with OVH Web hosting.

But you can use the OVH smtp server when using PHPMailer.

$mail->isSMTP();
$mail->Host = "ssl0.ovh.net";
$mail->Port = 465;
$mail->Username   = "yourmailovh";     
$mail->Password   = "yourpasswordovh";
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';

Hope it helps

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