为什么这个邮件系统不能在PHP中运行?

时间:2013-11-18 18:48:13

标签: php email

我正在尝试从我已经完成的表单中获取数据以通过电子邮件发送到我的个人电子邮件,所以每次填写后,它都会通过电子邮件发送给我,到目前为止我已经在php中编写了以下代码我网站上的部分,但是当我提交表单数据时,它会正确存储在变量中,但它不会向我发送信息吗?谁能告诉我我做错了什么?

<?php
$to = "example@hotmail.com"; //Removed personal email, didn't want to share publicly
$subject = "Form results";
$message = "Data from form"
. $firstname
. $surname
. $comments
. $email
. $password;

$from = "example@hotmail.com"; //removed this one too, but u get the idea
$headers = "From: " . $from;
mail($to,$subject,$message,$headers);
echo "mail Sent.";
?>

2 个答案:

答案 0 :(得分:3)

您可能需要此功能才能在WAMP服务器上启用电子邮件功能。

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

http://blog.techwheels.net/send-email-using-wamp-server/

请检查出来。

您的代码似乎没问题。

答案 1 :(得分:0)

尝试以下(对于Wampserver):

1-&gt;下载PHPmailer

2→

require_once("class.phpmailer.php");//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded        

    $mail = new PHPMailer();

    $mail->CharSet = 'utf-8';

    $mail->IsSMTP(); // telling the class to use SMTP
    $mail->Host       = "smtp.gmail.com"; // GMail SMTP server(to send messages from GMail)
    $mail->SMTPDebug  = 1;                     // enables SMTP debug information (for testing)
                                       // 1 = errors and messages
                                       // 2 = messages only
    $mail->SMTPAuth   = true;
    $mail->SMTPSecure = "ssl";
    $mail->Host       = "smtp.gmail.com";
    $mail->Port       = 465;
    $mail->Username   = "YOUR GMAIL EMAIL-ID";
    $mail->Password   = "YOUR GMAIL PASSWORD";

    $mail->SetFrom('YOUR GMAIL ID', 'ANY NAME');

    $mail->AddReplyTo('YOUR GMAIL ID', 'ANY NAME');


    $mail->AddAddress("RECEPIENTS GMAIL ID","ANY NAME");

    $mail->Subject = "ADD SUBJECT";

    $mail->Body ="message";

3→打开扩展php_openssl.To打开它点击WAMP 图标&gt; PHP&gt; PHP扩展&gt; php_openssl