2016-08-15 45 views
0

我有以下代碼工作,但沒有辦法,我希望它mail()函數不會正常工作

if(isset($_POST['edit']) && $_POST['edit']!="") 
{ 
    // Email Information 
    $firstName = $_POST['fname']; 
    $lastName = $_POST['lname']; 
    $mobile = $_POST['contactNumber']; 
    $comments = $_POST['message']; 
    $email_from = $_POST['email']; 
    $email_to = "[email protected]"; 
    //$email_headers = "From: ". $firstName ." ". $lastName . " <" . $email_from . ">\r\n" . "Reply-To: [email protected]"; 
    $email_headers = "From: $firstName $lastName <[email protected]>" . "\r\n" . "Reply-To: [email protected]"; 


    $email_subject = "Munster Wedding DJs Inquiry!"; 
    $email_body = "\nName: " . $firstName . " " . $lastName . 
    "\nEmail: " . $email_from . 
    "\nPhone Number: " . $mobile . 
    "\nMessage: " . $comments; 

    // Send Email 
    $mailerResult = @mail($email_to, "$email_subject", $email_body, 
    $email_headers, '-f ' . $email_from); 

    // Check For Errors 
    if($mailerResult) { 

     //echo "Mail Sent!"; 
     echo '<script>document.location.href="thanks.html#anchor"</script>'; 
     exit(); 

    } else { 

     // echo "Error Sending Email!" . "<br><br>"; 
     // print_r(error_get_last()); 
    } 

} 

如果我改變

From: $firstName $lastName <[email protected]>" 

From: $firstName $lastName <$email_from>" 

的表格不發送電子郵件? 這是爲什麼?

我想要做的就是收到電子郵件,當我點擊回覆時,會將用戶的電子郵件地址放入「到」字段。

+0

'如果我從$:$ firstName $ lastName「更改爲From:$ firstName $ lastName」'?兩者有什麼區別? –

+0

「From:$ firstName $ lastName」to From:$ firstName $ lastName「你是什麼意思?它們都是一樣的東西 –

回答

0

試試像這樣使用, & lt; for < & gt;爲>

除去& LT之間的空間;

$email_headers = "From: $firstName $lastName &lt; $email_from &gt;" . "\r\n" . "Reply-To: [email protected]"; 
+0

郵件頭!= sgml(html) – Sylwester