从xampp(本地主机)发送电子邮件

时间:2014-12-27 16:09:35

标签: php apache email xampp

我一直在尝试从php文件发送电子邮件。我配置了一些xampp文件,但仍然无法正常工作,我无法确定问题出在哪里。我在网上关注的不仅仅是一个教程,但仍然没有用。

这是我的php.ini

[mail function]
; XAMPP: Comment out this if you want to work with an SMTP Server like Mercury
;SMTP = smtp.gmail.com
smtp_port = 587

; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = postmaster@localhost


; XAMPP: Comment out this if you want to work with fakemail for forwarding to your mailbox (sendmail.exe in the sendmail folder)
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"

; XAMPP: Comment out this if you want to work with mailToDisk, It writes all mails in the C:\xampp\mailoutput folder
;sendmail_path="C:\xampp\mailtodisk\mailtodisk.exe"

mail.add_x_header=Off

这里是sendmail.ini

[sendmail]


smtp_server=smtp.gmail.com

; smtp port (normally 25)

smtp_port=587


smtp_ssl=auto


error_logfile=error.log



; if your smtp server requires authentication, modify the following two lines

auth_username=user@gmail.com    
auth_password=xxxxxxx

; if your smtp server uses pop3 before smtp authentication, modify the 
; following three lines.  do not enable unless it is required.

pop3_server=
pop3_username=
pop3_password=

; force the sender to always be the following email address
; this will only affect the "MAIL FROM" command, it won't modify 
; the "From: " header of the message content

force_sender=user@gmail.com

这是我的php发送代码

<?php
$to = "user2@gmail.com";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
$headers = "From: user@gmail.com" . "\r\n";
if (mail($to, $subject, $body, $headers)) {
    echo ("Message successfully sent!");
} else {
    echo ("Message delivery failed...");
}
?>

0 个答案:

没有答案
相关问题