在PHP中使用SMTP时“无法连接到邮件服务器”

时间:2016-12-21 10:47:57

标签: php email wamp

我正在尝试从一个电子邮件地址向另一个电子邮件地址发送邮件。但徒劳无功。它显示错误。

我的PhP代码在这里:

<?php  

 $to='r@domainname.com'; 
 $subject='Email from website viewers!';

 ini_set("SMTP","smtp.gmail.com");
 ini_set("smtp_port","25");

 ini_set('sendmail_from', 'abc@gmail.com');

 if(isset($_POST['name'])){ $name = $_POST['name']; }
 if(isset($_POST['email'])){ $email = $_POST['email']; }  
 if(isset($_POST['topic'])){ $topic = $_POST['topic']; }  
 if(isset($_POST['message'])){ $message = $_POST['message']; }  

 $message = $name . " " . $email . " wrote the following:" . "\n\n" . $_POST['message'];

 $header = "From:" .$email;

 if($_POST) {       
     if($name==''|| $email==''||$message=='')   {
        $feedback = 'Please Fill out All the fields!';
     }
     else {
        mail($to, $subject, $message, $header);     
        $feedback = 'Thanks for your Email. We will contact you shortly.';  
     }

 }   
?>

php.ini文件如下:

[mail function]
; For Win32 only.
: http://php.net/smtp
;SMTP = smtp.gmail.com
; http://php.net/smtp-port
;smtp_port = 25

; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = abc@gmail.com

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path

sendmail_path ="C:\wamp\sendmail\sendmail.exe -t -i"

我的sendmail.ini文件如下:

[sendmail]

smtp_server= smtp.gmail.com
smtp_port=25
smtp_ssl=tls
error_logfile=error.log
debug_logfile=debug.log
auth_username= abc@gmail.com
auth_password= 123

请在这方面帮助我找到我的代码中的错误。

0 个答案:

没有答案