简体   繁体   中英

Send email with PHP/IIS

We're struggling with email submission via PHP. Currently we're using the following code:

<?php 
 ini_set('display_errors',1);
 ini_set("SMTP","smtp.gmail.com");
 ini_set("smtp_port","587");
 ini_set("auth_username","mymail_address@gmail.com");
 ini_set("auth_password","mypassword");
 

 $to      = 'mydestination_address@gmail.com';
 $subject = 'the subject';
 $message = 'hello';
 $headers = 'From: mymail_address@gmail.com';

 if(mail($to, $subject, $message, $headers))
 {
    echo "Success!";
 }else
 {
    echo "Failed.";
 }
?>

The outcome of the code gives the following message:

Warning: mail(): SMTP server response: 530 5.7.0 Must issue a STARTTLS command first. e22sm16110599edu.35 - gsmtp in C:\\inetpub\\production\\mailtest.php on line 13 failed.

Please note that our application has been created with PHP using IIS.

I think you can do it with:

ini_set("SMTP","ssl://smtp.gmail.com");
ini_set("smtp_port","465");

Please check if your PHP installation has SSL support before use the code above.

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