我如何使用PHP和xamp发送电子邮件?

时间:2018-02-20 15:05:53

标签: php xampp

我正在尝试创建一个代码,以便在按钮被阻塞时发送电子邮件,我通过更改php.ini的代码来禁用此http://php.net/manual/en/function.mail.php来创建代码和配置xamp,但是它说它无法连接到服务器:

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

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

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

和senmail.ini:

smtp_server=smtp.gmail.com
smtp_port=587
auth_username=myemail@gmail.com
 auth_password=myppass

我使用这个表单来调用php脚本:

 <form  action="/prototype/views/email-script.php" method="post">
     <p><input type="button"  name="orcrequest" id="orcrequest" value="Enviar Orçamento" class="btn btn-default">
     </form>

这是脚本:

<?php

if(isset($_POST['orcrequest']))
{

$to      = 'jun_otomo@hotmail.com'; //can receive notification

$subject = 'the subject';
$message = 'hello';
$headers = 'From: jun.atomo@gmail.com' . "\r\n" .
    'Reply-To: jun.atomo@gmail.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);

echo 'Email Sent.';
}

?>

0 个答案:

没有答案