我有一个 Award Space Mail Hosting 帐户。我只为免费电子邮件发送功能创建了该帐户。试过了
PHP mailer
swiftmailer ect..
但没有用。谁能给我一个完整的 php 和邮件表单的工作代码,这样我就可以在我的服务器上测试它。我可以在使用这个文件时发送电子邮件:
http://www.html-form-guide.com/php-form/php-form-validation.html
但是,我不想要代码的平静。我想要一个可以在我的服务器上运行的完美代码。
示例代码:(有一个html表单提交表单)
<?php
if(isset($_POST['submit'])) {
$myemail = “support@domain.dx.am”;
$subject = $_POST['subject'];
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$headers = “From:Contact Form <$myemail>\r\n”;
$headers .= “Reply-To: $name <$email>\r\n”;
echo “Your message has been sent successfully!”;
mail($myemail, $subject, $message, $headers);
} else {
echo “An error occurred during the submission of your message”;
}
?>
或者我尝试用 php mailer 做同样的事情:
<?php
require 'filefolder/mailer/class.phpmailer.php';
$mail = new PHPMailer;
$mail->IsSMTP(); // Set mailer to use SMTP
$mail->Host = 'localhost'; // Specify main and backup server
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'support@whatever.dx.am'; // SMTP username
$mail->Password = 'mypassword'; // SMTP password
$mail->From = 'support@whatever.dx.am';
$mail->FromName = 'Support';
$mail->AddAddress('anything@gmail.com'… // Name is optional
$mail->WordWrap = 50; // Set word wrap to 50 characters
$mail->IsHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->Send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
echo 'Message has been sent';
?>
我做错了什么。但想不通是什么。谁能帮我吗 。