简体   繁体   English

未为 SMTP 电子邮件正确设置联系表单 PHP 文件且未发送

[英]Contact form PHP file not set properly for SMTP email and not sending

I've set up an email form on my site, added the php file, but it won't send the form to my email address.我在我的网站上设置了一个电子邮件表单,添加了 php 文件,但它不会将表单发送到我的电子邮件地址。 I contacted my webhost and they replied with "You would need to use a script which supports SMTP for sending not sendmail() which is what the current script is using".我联系了我的网络主机,他们回答说“您需要使用支持 SMTP 的脚本来发送,而不是使用当前脚本使用的 sendmail()”。 What does this mean?这是什么意思? Have I set up my php file wrong?我是否设置了错误的 php 文件? I've included my php file below.我在下面包含了我的 php 文件。 The form is currently hosted here http://www.rockclick.co.uk/contact.htm该表格目前托管在这里http://www.rockclick.co.uk/contact.htm

<script><?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$subject = $_POST['subject'];
header('Content-Type: application/json');
if ($name === ''){
print json_encode(array('message' => 'Name cannot be empty', 'code' =>    0));
exit();
}
if ($email === ''){
print json_encode(array('message' => 'Email cannot be empty', 'code' =>   0));
exit();
} else {
if (!filter_var($email, FILTER_VALIDATE_EMAIL)){
print json_encode(array('message' => 'Email format invalid.', 'code' => 0));
exit();
}
}
if ($subject === ''){
print json_encode(array('message' => 'Subject cannot be empty', 'code' => 0));
exit();
}
if ($message === ''){
print json_encode(array('message' => 'Message cannot be empty', 'code'   => 0));
exit();
}
$content="From: $name \nEmail: $email \nMessage: $message";
$recipient = "enquiries@rockclick.co.uk";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $content, $mailheader) or die("Error!");
print json_encode(array('message' => 'Email successfully sent!', 'code'   => 1));
exit();
?></script>

I wasn't able to get this to work in the end so gave up and removed the form completely.我最终无法使其正常工作,因此放弃并完全删除了表单。 It appears my web hosting doesn't support email forms.看来我的虚拟主机不支持电子邮件表单。 If anyone has a working email form which sends an email to a gmail address then please feel free to post it here!如果有人有一个可以发送电子邮件到 Gmail 地址的有效电子邮件表单,请随时在此处发布! I googled and have literally spent all day on it and it's beaten me.我在谷歌上搜索并花了一整天的时间,它打败了我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM