我一直在努力使用这个php脚本,基本上我想在用户通过执行php提交表单时发送电子邮件。我对php语言很新,我不确定是否是阻止电子邮件发送的webhost,或者我的php配置是错误的(我不知道要更改配置)。我发现我的PHP代码没有任何问题,并希望你们可以分享一些帮助。
我已经通过localhost提交了表单,其中发送完美,但是当连接到我的webhost时,它只会警告出现问题。
我已经搜索了其他各种问题,但我没有管理,我将不胜感激。我已经将php插入到html代码中但实际上应该是一个外部文件,我只是不知道在stackoverflow上插入php编码的位置。
form {
margin: 0 auto;
width: 80%;
height: auto;
}
/*Style the text boxes*/
input,
textarea {
width: 80%;
height: 20px;
background-color: #efefef;
border: 1px solid #dedede;
-moz-box-sizing: content-box;
box-sizing: content-box;
padding: 10px;
margin-top: 3px;
font-size: 0.9em;
font-family: Baskerville, "Palatino Linotype", Palatino, "Century Schoolbook L", "Times New Roman", serif;
color: #3a3a3a;
border-radius: 5px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
}
input:focus,
textarea:focus {
border: 1px solid #97d6eb;
}
textarea {
height: 213px;
width: 90%;
}
#submit,
#reset {
width: 10%;
height: 38px;
background-color: #161616;
color: #FFFFFF;
border: none;
margin-top: 20px;
cursor: pointer;
}
#submit:hover,
#reset:hover {
opacity: 0.9;
color: #755378;
}
<!doctype html>
<html lang="en">
<head>
</head>
<body>
<form method="POST" action="index.php" target="" accept="text/html" formenctype="multipart/form-data">
<label>Name & Surname:</label>
<input name="name" placeholder="Type Here..." required="">
<label>Email:</label>
<input name="email" type="email" placeholder="Type Here..." required="">
<label>Subject:</label>
<input name="subject" placeholder="Tour your interested in:">
<label>Message:</label>
<textarea name="message" placeholder="Inquiry"></textarea>
<input id="submit" name="submit" type="submit" value="Submit">
<input id="reset" name="reset" type="reset" value="Reset">
</form>
<?php
error_reporting(-1);
ini_set('display_errors', 'On');
set_error_handler("var_dump");
ini_set("mail.log", "/tmp/mail.log");
ini_set("mail.add_x_header", TRUE);
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: ';
$to = 'eleccon@global.co.za';
$subject = $_POST['subject'];
$body = " From: $name\n E-mail: $email\n Subject: $subject\n Message:\n $message";
if (isset($_POST['submit']))
{
/* Anything that goes in here is only performed if the form is submitted */
if (mail ('eleccon@global.co.za', $subject, $body, $from))
{
echo "<script type='text/javascript'>alert('Your Message has been sent! Press OK to continue');</script>";
} else
{
echo "<script type='text/javascript'>alert('Something went wrong, go back and try again');</script>";
}
}
?>
</body>