【发布时间】:2019-11-18 05:55:58
【问题描述】:
我有 PHP 电子邮件表单,我想使用 PHP 表单发送电子邮件,但这不起作用。
HTML:-
<form action="mail_handler.php" method="post" name="form" class="form-box">
<label for="name">Name</label><br>
<input type="text" name="name" class="inp" placeholder="Enter Your Name" required><br>
<label for="email">Email ID</label><br>
<input type="email" name="email" class="inp" placeholder="Enter Your Email" required><br>
<label for="phone">Phone</label><br>
<input type="tel" name="phone" class="inp" placeholder="Enter Your Phone" required><br>
<label for="message">Message</label><br>
<textarea name="msg" class="msg-box" placeholder="Enter Your Message Here..." required></textarea><br>
<input type="submit" name="submit" value="Send" class="sub-btn">
</form>
PHP:-
<?php
if(isset($_POST['submit'])){
$name=$_POST['name'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$msg=$_POST['msg'];
$to='123@gmail.com'; // Receiver Email ID, Replace with your email ID
$subject='Form Submission';
$message="Name :".$name."Phone :".$phone."Wrote the following :".$msg;
$headers="From: ".$email;
if(mail($to, $subject, $message, $headers)){
echo "<h1>Sent Successfully! Thank you, We will contact you shortly!</h1>";
}
else{
echo "Something went wrong!";
}
}
?>
我们将不胜感激!
【问题讨论】:
-
你遇到了什么错误?
-
可能是你的smtp服务器没有设置什么的,试试
error_get_last(); -
不是 PHP 播放器,但只是提出一点,PHP 的
mail函数不是那么好,并且在发送电子邮件或我说接收时运气不好。我需要切换PhpMailer -
你从服务器或本地主机得到什么错误。有时描述发生的错误消息超过 70 个字母,您需要将其包装起来。因为每一行都应该用 LF (\n) 分隔,并且行不应超过 70 个字符。使用下面的代码来包装消息。
$message = wordwrap($message,70);将包装邮件。 -
我收到错误“出了点问题!”