Php 仅向特定用户发送电子邮件

Php 仅向特定用户发送电子邮件,php,email,Php,Email,任何人都可以告诉我,为什么我为$email_发送的某些电子邮件会收到该电子邮件,而我发送的其他电子邮件却无法收到。 对不起,我是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

任何人都可以告诉我,为什么我为$email_发送的某些电子邮件会收到该电子邮件,而我发送的其他电子邮件却无法收到。 对不起,我是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
}
 ?>

电子邮件发件人:
主题:
消息:


您需要使用
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;
    ?> 

Hi Chirag,感谢您的回复。让我测试一下,看看它是否适合我。再次感谢!干杯