用wamp设置电子邮件

时间:2014-03-11 11:14:52

标签: javascript php html wamp

我见过很多网站模板都有基于AJAX的联系表单,当你点击提交发送邮件时,他们说它实际上并没有发送邮件, 我想将这个系统实现为我正在构建的模板。

我已经安装了wamp,还准备好了模板和php文件我不知道接下来该做什么。 php文件:http://pastebin.com/YGGK7xsH

javascript文件:http://pastebin.com/RM2TNFNX

2 个答案:

答案 0 :(得分:0)

您无法使用WAMP发送邮件,因为它是本地服务器。

请查看此帖子以获取更多信息和解决方案:Send email from localhost running XAMMP in PHP using GMAIL mail server

答案 1 :(得分:0)

使用sendmail从localhost / WAMP服务器发送电子邮件

此解决方案需要sendmail.exe(一个命令行界面(CLI)可执行文件,它接受来自PHP的电子邮件,连接到SMTP服务器并发送电子邮件)。您不需要按命令使用它,也不要为此烦恼:-) Download the sendmail.zip并按照以下步骤操作:

Create a folder named “sendmail” in “C:\wamp\”.
    Extract these 4 files in “sendmail” folder: “sendmail.exe”, “libeay32.dll”, “ssleay32.dll” and “sendmail.ini”.
    Open the “sendmail.ini” file and configure it as following
        smtp_server=smtp.gmail.com
        smtp_port=465
        smtp_ssl=ssl
        default_domain=localhost
        error_logfile=error.log
        debug_logfile=debug.log
        auth_username=[your_gmail_account_username]@gmail.com
        auth_password=[your_gmail_account_password]
        pop3_server=
        pop3_username=
        pop3_password=
        force_sender=
        force_recipient=
        hostname=localhost

您无需为这些属性指定任何值:pop3_server,pop3_username,pop3_password,force_sender,force_recipient。如果您已经发送了成功的电子邮件,则error_logfile和debug_logfile设置应保持空白,否则此文件的大小将不断增加。如果您无法使用sendmail发送电子邮件,请启用这些日志文件设置。

在您的GMail设置中启用IMAP访问 - >转发和POP / IMAP - > IMAP访问

在Apache服务器中启用“ssl_module”模块

为PHP编译器启用“php_openssl”和“php_sockets”扩展

从“C:\ wamp \ bin \ apache \ Apache2.2.17 \ bin”打开php.ini并将其配置为以下 (“C:\ wamp \ bin \ php \ php5.3.x”中的php.ini不起作用) (您只需要在以下代码中配置最后一行,在分号(;)前面加上其他行

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

; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = you@domain.com

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

重启WAMP服务器。

创建一个PHP文件并在其中编写以下代码:

<?php
$to       = 'recipient@yahoo.com';
$subject  = 'Testing sendmail.exe';
$message  = 'Hi, you just received an email using sendmail!';
$headers  = 'From: sender@gmail.com' . "\r\n" .
            'Reply-To: sender@gmail.com' . "\r\n" .
            'MIME-Version: 1.0' . "\r\n" .
            'Content-type: text/html; charset=iso-8859-1' . "\r\n" .
            'X-Mailer: PHP/' . phpversion();
if(mail($to, $subject, $message, $headers))
    echo "Email sent";
else
    echo "Email sending failed";
?>

在$ to和$ headers变量中进行适当的更改,以设置收件人,发件人和回复地址。将其另存为“send-mail.php”。 (您可以将它保存在“C:\ wamp \ www”中的任何子文件夹中。) 在浏览器中打开此文件,它现在必须正常工作

参考链接http://blog.techwheels.net/send-email-from-localhost-wamp-server-using-sendmail/

相关问题