php mail()函数无法使用gmail

时间:2011-06-26 04:35:46

标签: php

PFB我的代码

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

    $x = $_POST['yourname'];


    $email = $_POST['email'];
    $msg="Your Name is $x.";
    $to='abc@gmail.com';
    $sub='Your information';
    $header = "From: ". $x . " <" . $email . ">\r\n";
    ini_set("SMTP","smtp.gmail.com" );
    ini_set('sendmail_from', 'abc@gmail.com');
    //$email is entered as abc@gmail.com
    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>

我用我的Gmail帐户(POP / SMTP)配置了我的Outlook 2007。 并且php.ini设置为SMTP = smtp.gmail.com smtp_port = 587.这些设置也与outlook设置匹配。

我的浏览器仍然显示“失败”。 请帮忙。

1 个答案:

答案 0 :(得分:3)

您需要使用“ssl”从Gmail发送电子邮件。你可以下载PhPmailer,可以看到他们为gmail提供的样本。

相关问题