仅向某些用户发送电子邮件

时间:2015-10-16 10:36:07

标签: php email

任何人都可以告诉我为什么我为$ email_to发送的某些电子邮件会收到该电子邮件,而我发送的其他电子邮件则无法收到。 对不起,PHP脚本新手。

<?php
print "<h2>Simple Contact Form</h2><br/><br/>";
$email_to = "booked@domain.com";

//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
}
 ?>

1 个答案:

答案 0 :(得分:0)

您需要使用php mailer才能使其正常工作

您必须拥有具有特权的电子邮件地址。就像你主持电子邮件......

下载phpmailer并将其添加到您的代码中,以便您可以发送邮件.. 这是我使用的一些引用代码...

<?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;
    ?>