2015-10-16 94 views
-1

任何人都可以知道爲什麼我給$ email_to的某些電子郵件會收到電子郵件,而我放的其他電子郵件無法收到。 對不起,PHP腳本的新手。只發郵件給某些用戶

<?php 
print "<h2>Simple Contact Form</h2><br/><br/>"; 
$email_to = "[email protected]"; 

//if "email_from" variable is filled out, send email 
if (isset($_REQUEST['email_from'])) { 
$email_from = $_REQUEST['email_from']; 
$subject = $_REQUEST['subject']; 
$comment = $_REQUEST['comment']; 
//send email 
mail($email_to, "$subject", $comment, "From:" . $email_from); 
//Email response 
echo "Thank you for contacting us!"; 
} 
//if "email_from" variable is not filled out, display the form 
else { 
?> 
<form method="post"> 
Email From: <input name="email_from" type="text" /><br /> 
Subject: <input name="subject" type="text" /><br /> 
Message:<br /> 
<textarea name="comment" rows="15" cols="40"></textarea><br /> 
<input type="submit" value="Submit" /> 
</form> 
<?php 
} 
?> 

回答

0

您需要使用php mailer,使其工作

您必須有電子郵件地址與特權。就像你HV託管電子郵件...

下載PHPMailer的,你的代碼中添加它,這樣你可以發送郵件.. 這裏是用來通過我的一些rference代碼...

<?php 

require("PHPMailer/class.phpmailer.php"); 
require("PHPMailer/PHPMailerAutoload.php"); 

define("MAILHOST",'hostsite '); 
define("MAILSMTPAuth",true); 
define("MAILUsername",'hosting mail'); 
define("MAILPassword",'password'); 
define("MAILSMTPSecure",'ssl'); 
define("MAILPort",portno); 
define("MAILFrom",'hosting mail'); 
    $mail = new phpmailer(); 
    $result = array(); 

    $mail->isSMTP();          // Set mailer to use SMTP 
    $mail->Host = MAILHOST; // Specify main and backup SMTP servers 
    $mail->SMTPAuth = MAILSMTPAuth;        // Enable SMTP authentication 
    $mail->Username = MAILUsername;     // SMTP username 
    $mail->Password = MAILPassword;       // SMTP password 
    $mail->SMTPSecure = MAILSMTPSecure;       // Enable TLS encryption, `ssl` also accepted 
    $mail->Port = MAILPort;         // TCP port to connect to 

    $mail->From = MAILUsername; 
    $mail->FromName = 'Name'; 
    $mail->isHTML(true); // Set email format to HTML 

    $mail->Subject = " Inquiry Form"; 

    $mail->Body = "message";   


    $mail->SetFrom('hosting mail address', 'name'); 
    $mail->addAddress('recieving mail address', 'Name');  // Add a recipient admin 


     } 
    exit; 
    ?> 
+0

喜Chirag,感謝您的回覆。讓我測試一下,看看它對我有用。再次感謝!乾杯。 –

+0

如果有幫助,然後接受我的答案 –

相關問題