我无法运行php。它没有向我的帐户发送任何电子邮件。
我是学习php的新手。我对html和CSS有基本的了解。我不知道如何完成此操作。香港专业教育学院试图复制其他人的代码并使其适应我的要求。
php代码:
<?php
if(isset($_POST['submit'])){
$name=$_POST['name'];
$email=$_POST['email'];
//send mail
$to='dadjus555@gmail.com';
$subject='New ';
$body='<html>
<body>
<h3>Feedback</h3>
<hr>
<p> Name : '.$name.'</p>
<br>
<p> Job : '.$job.'</p>
<br>
<p> Co : '.$co'</p>
<br>
<p> Phone : '.$phone.'</p>
<br>
<p> Email : '.$email.'</p>
<br>
<p> Snapchat : '.$snap.'</p>
<br>
<p> Instagram : '.$insta.'</p>
<br>
<p> Facebook : '.$facebook.'</p>
<br>
<p> Twitter : '.$twitter.'</p>
<br>
</body>
</html>';
$headers ="From:".$name."<".$email.">\r\n";
$headers .="reply-To:".$email."\r\n";
$headers .="NINE-Version: 1.0\r\n";
$headers .="Content-type: text/html; charset=utf-8";
//sending process
$send=mail($to, $subject, $body, $headers);
$confirm=mail($user, $usersubject, $userheaders,$usermessage );
if($send && $confirm){
echo "success";
}
else{
echo "Failed";
}
}
?>
HTML代码:
<form>
<fieldset><legend>Personal</legend>
<label for="field1"><span>Name <span class="required">*</span></span><input
type="text" class="input-field" name="name" value="" /></label>
<label for="field1"><span>Occupation</span></span><input type="text"
class="input-field" name="job" value="" /></label>
<label for="field1"><span>what company?</span></span><input type="text"
class="input-field" name="co" value="" /></label>
<label for="field1"><span>Phone <span class="required">*</span></span><input
type="text" class="input-field" name="phone" value="" /></label>
<label for="field2"><span>Email <span class="required">*</span></span><input
type="email" class="input-field" name="email" value="" /></label>
<label for="field1"><span>Snapchat </span></span><input type="text"
class="input-field" name="snap" value="" /></label>
<label for="field1"><span>Instagram </span></span><input type="text"
class="input-field" name="insta" value="" /></label>
<label for="field1"><span>Facebook </span></span><input type="text"
class="input-field" name="facebook" value="" /></label>
<label for="field1"><span>Twitter </span></span><input type="text"
class="input-field" name="twitter" value="" /></label>
<label for="field3"><span>Kik</span></span><input type="text" class="input-
field" name="kik" value="" /></label>
</label>
</fieldset>
</form>
当有人在表单中输入文字并按下“提交”按钮时,信息将通过电子邮件发送到我的收件箱中
答案 0 :(得分:0)
由于某些错误,您无法发送/接收邮件:
在这里您可以看到我的更改:
$headers = "From: $name <$email>\r\n";
$headers .= "Reply-To: $name <$email>\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=utf-8";
// sending process
$send = mail($to, $subject, $body, $headers);
$confirm = mail($user, $usersubject, $usermessage, $userheaders);
if ($send && $confirm) {
echo "success";
} else {
echo "Failed";
}
这些变量是否存在?
$user
$usersubject
$usermessage
$userheaders
如您在第2点所见,您致电:
mail($user, $usersubject, $userheaders,$usermessage );
同时应为:
mail($user, $usersubject, $usermessage, $userheaders);
因此您无法检查并从php获得正确的响应。
我建议将这两个邮件分开...
if ($send) {
echo "1st mail sent with success";
} else {
echo "1st mail is failed";
}
if ($confirm) {
echo "2nd mail sent with success";
} else {
echo "2nd mail is failed";
}
我希望这会有所帮助。