簡體   English   中英

PHP:郵件未發送

[英]PHP: Mail not sent

我正在嘗試以下代碼,但始終顯示“ Mail not sent 我如何找到真正的問題? 代碼如下:

    $full_name = htmlspecialchars(trim($_POST['full_name']));
    $email = htmlspecialchars(trim($_POST['email']));
    $phone = htmlspecialchars(trim($_POST['phone']));
    $message = htmlspecialchars(trim($_POST['message']));

$to = "mail@example.com";


$subject = $full_name . ' is interested to have a business discussion with you';

$headers = "From: " . strip_tags($_POST['email']) . "\r\n";
$headers .= "Reply-To: " . strip_tags($_POST['email']) . "\r\n";
//    $headers .= "CC: susan@example.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

$message = '<html><body>';
$message .= '<h3>Full Name: </h3>: ' . $full_name . '<br>';
$message .= '<h3>Phone: </h3>: ' . $phone . '<br>';
$message .= '<h3>Message: </h3>: ' . $message . '<br><br>=======================<br>';
$message .= '<h3>IP Address: </h3>: ' . $ip . '<br>';
$message .= '</body></html>';

if(mail($to, $subject, $message, $headers))
{
    echo "Mail Sent Successfully";
}else{
    echo " Mail Not Sent";
}

試試此代碼,希望對您有所幫助。

 <?php //print_r($_POST); //$fname = $_POST['fname']; //$lname = $_POST['lname']; //$email = $_POST['email']; //$message = $_POST['message']; if(isset($_POST['fname']) && $_POST['fname'] != ''){ $fname = $_POST['fname']; } if(isset($_POST['lname']) && $_POST['lname'] != ''){ $lname = $_POST['lname'];//phone number } if(isset($_POST['email']) && $_POST['email'] != ''){ $email = $_POST['email']; } if(isset($_POST['message']) && $_POST['message'] != ''){ $com = $_POST['message']; } $to = 'noreply@noreply.com'; $subject = 'Site Visiter.'; // message $message = sprintf("Site visiter details: <br>Name:- %s <br> Phone:- %s <br> Email:- %s<br> Message:- %s",$fname,$lname,$email,$com); // To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\\r\\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\\r\\n"; // Additional headers $headers .= 'To: Mary <nb158f@gmail.com>' . "\\r\\n"; $headers .= 'From: mysite.com <admin@site.com>' . "\\r\\n"; //$headers .= 'Cc: divakar.k@gmail.com' . "\\r\\n"; // Mail it $flag = mail($to, $subject, $message, $headers); echo '<script>alert("Mail Sent :");</script>'; echo '<script>window.location.href="index.php";</script>'; 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM