PHP - 为什么我的电子邮件发送代码不起作用?

时间:2015-08-21 03:50:26

标签: php email

你可以在标题上看到。 我将在这里发布我的代码..如果我完成代码,请取悦我

<?php
$name  = $_REQUEST["name"];
$email = $_REQUEST["email"];
$mobile = $_REQUEST["mobile"];
//$msg   = $_REQUEST["msg"];
$to    = "email@email.com"; // <--- Change email ID here
if (isset($email) && isset($name)) {
$subject = "Cadastro para Pos Graduacao em Lideranca e Gestao Sustentavel";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= "From: <".$email.">\r\n"."Reply-To: ".$email."\r\n" ;
$msg     = "From: Email: $email <br/>Mobile: $mobile" ; //<br/>Message: $msg

   $mail =  mail($to, $subject, $msg, $headers);
  if($mail)
    {
        echo 'success';
    }

else
    {
        echo 'failed';
    }
}

?>

嗯..这些代码适用于其他项目..所以我不知道我做错了什么..

1 个答案:

答案 0 :(得分:0)

if(isset($_REQUEST['email']) && !empty($_REQUEST['email']))  {


$name  = $_REQUEST["name"];
$email = $_REQUEST["email"];
$mobile = $_REQUEST["mobile"];


$headers  = "From: information <".$email.">\n"; 
$headers .= 'MIME-Version: 1.0' . "\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\n";
$to='email@email.com';
$subject = 'subjenct';
$message =   "<html>
    <body>
     <p style='font-family:verdana; font-size:12px; margin:30px 0 0 30px; align=center'>
     <strong> Information </strong> <br>
      <strong>Full Name: </strong> ".$name."<br>
      <strong>Email: </strong> ".$email."<br>
      <strong>Mobile: </strong> ".$mobile."<br>
     </p>
    </body>
     </html>";

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

}

if($res)
{
echo 'success';
}
else
{
    echo 'failed';
}