简体   繁体   English

我的联系表格php不会通过smtp向我的gmail帐户发送电子邮件

[英]my contact form php won't send an email via smtp to my gmail account

I am trying to insert the php code SMTP via gmail so it can send through smtp.gmail.com, and it doesn't seem to work. 我正在尝试通过gmail插入php代码SMTP,以便它可以通过smtp.gmail.com发送,而且似乎无法正常工作。 I someone can give me a hand so I can get it working, it would be a great help. 我有人可以帮忙,这样我就可以工作,这将是很大的帮助。

ps with out this scrpit it works on a server that already has the smtp setup. 带有此脚本的ps可以在已经具有smtp设置的服务器上工作。 I am trying to insert it so I can use it on another server with out mail server. 我试图将其插入,以便可以在没有邮件服务器的其他服务器上使用它。

  `($host = "ssl://smtp.gmail.com";
$port = "465";
$username = "<wilkinsonsport2014@gmail.com>";
$password = "********";)`

` `

    $host = "ssl://smtp.gmail.com";
$port = "465";
$username = "<wilkinsonsport2014@gmail.com>";
$password = "********";

$mail_to = 'wilkinsonsport2014@gmail.com'; 

$name = $_POST['sender-name'];
$mail_from = $_POST['sender-email'];
$phone = $_POST['sender-phone'];
$message = $_POST['sender-message'];

$subject = 'localhost/wilkinson-sport Messaggio da un visitatore ' . $name;

$body_message .= 'Da: ' . $name . "\r\n";
$body_message .= 'E-mail: ' . $mail_from . "\r\n";
$body_message .= 'Telfono: ' . $phone . "\r\n";
$body_message .= 'Commenti: ' . $message;


$headers .= 'Da: ' . $mail_from . "\r\n";
$headers .= 'Rispondi a: ' . $mail_from . "\r\n";

$mail_sent = mail($mail_to, $subject, $body_message, $headers); 

if ($mail_sent == true){ 

if (isset($_POST) && $_POST['accetto'] == "si")
{               
    echo ("<script>alert('Hai accettato il consenso privacy.')</script>");
}
else if (isset($_POST) && $_POST['accetto'] == "no")
{
    echo ("<script>alert('Non hai accettato il consenso privacy. Riprova!')</script>");
}
else if (isset($_POST) && $_POST['entra'] == false)
{
    echo ("<script>alert('Devi accettare il consenso privacy per accedere!')</script>");
} 
} 


?>`

尝试使用PHPMailer,这是用于邮件传输的类https://github.com/PHPMailer/PHPMailer

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM