2011-06-26 34 views
0

PFB工作我的代碼PHP的mail()函數與Gmail沒有

<html> 
    <head> 
     <title> Your information</title> 
    </head> 
    <body> 
    <?php 

    $x = $_POST['yourname']; 


    $email = $_POST['email']; 
    $msg="Your Name is $x."; 
    $to='[email protected]'; 
    $sub='Your information'; 
    $header = "From: ". $x . " <" . $email . ">\r\n"; 
    ini_set("SMTP","smtp.gmail.com"); 
    ini_set('sendmail_from', '[email protected]'); 
    //$email is entered as [email protected] 
    if(mail($to, $sub, $msg,'From:' . $email)){ 
     echo 'success'; 
    } 
    else{ 
     echo 'failure'; 
    } 


echo 'Thanks for submitting your information<br/>'; 
echo 'Your Name ' . $x . '<br/>' ; 
echo 'Email ' . $email . '<br/>' ; 
echo $msg; 
?> 
    </body> 
</html> 

我hqve配置我的Outlook 2007年與我的Gmail帳戶(POP/SMTP)。 和php.ini設置爲SMTP = smtp.gmail.com smtp_port = 587.這些設置也與Outlook設置匹配。

仍然我得到的是「失敗」在我的瀏覽器上打印。 請幫忙。

回答

3

您需要使用「ssl」從Gmail發送電子郵件。您可以下載PhPmailer並查看他們爲Gmail提供的樣本。