![](/img/trans.png)
[英]problems in sending and receiving emails by contact form 7 in wordpress
[英]PHP contact form sending but not receiving emails
我已經使用PHP創建了聯系表格來發送數據。 表單似乎發送正常,因為沒有錯誤並且顯示成功消息,但是我沒有將電子郵件接收到指定的收件箱中。
我使用的是PHPMailer,因為我最初只是嘗試使用php'mail'命令,但現在我知道這有點麻煩。
我不明白為什么我不接收電子郵件,所以我非常感謝可以提供的任何幫助。
我對PHP還是很陌生,所以請耐心等待:)
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
$msg = "";
if (isset($_POST['submit'])) {
require 'phpmailer/src/Exception.php';
require 'phpmailer/src/PHPMailer.php';
require 'phpmailer/src/SMTP.php';
function sendemail ($to, $from, $body) {
$mail = new PHPMailer(true);
$mail->setFrom($from);
$mail->addAddress($to);
$mail->Subject = 'Contact Form - Email';
$mail->Body = $body;
$mail->IsHTML(false);
return $mail->send();
}
$email = $_POST['email'];
$subject = $_POST['subject'];
$body = $_POST['body'];
if (sendemail('gareth.langley1@gmail.com', $email, $subject, $body)) {
$msg = 'Email has been sent, thank you!';
} else
$msg = 'Email failed, please try again later';
}
?>
<title>Test Contact Form Using PHPMailer</title>
<body>
<div id="contactInnerWrapper">
<a href="#"><span id="close">×</span></a>
<h1 id="h1contactForm">Get in touch</h1>
<form method="post" action="index.php">
<label for="email">Email address:</label><br>
<input type="email" name="email" placeholder="Enter email" id="email">
<label for="subject">Subject:</label>
<input type="text" name="subject" id="subject"><br>
<label for="body">What would you like to ask us?</label><br>
<textarea type="text" name="body" rows="7" id="content"></textarea>
<button type="submit" name="submit" id="submit">Submit</button>
</form>
<br><br>
<?php echo $msg; ?>
</div>
</body>
您要將4個參數傳遞給只需要3個的函數。
function sendemail ($to, $from, $body)
sendemail('gareth.langley1@gmail.com', $email, $subject, $body)
嘗試像這樣編輯:
if (sendemail('gareth.langley1@gmail.com', $email, $body)) {
$msg = 'Email has been sent, thank you!';
} else
$msg = 'Email failed, please try again later';
}
您的服務器很可能沒有安裝或安裝了郵件傳輸代理(MTA),但未正確配置。 適用於Linux的MTA示例:sendmail,postfix,exim4,qmail。
安裝和配置MTA可能會變得很復雜。
您可以從同一服務器上的命令行發送電子郵件嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.