【发布时间】:2014-09-04 02:42:08
【问题描述】:
我最近移动了主机,现在通过联系表单我必须使用 SMTP。我已经能够在一些帮助下完成工作,但无法从表单中检索到我需要的信息。我试图提取的信息是姓名电子邮件电话和消息。这是我一直在使用的
<?php
require "email.php";
$mail = new EMail;
$mail->Username = 'username.co.uk';
$mail->Password = 'mypassword';
$mail->SetFrom("no-reply@mywebsite.co.uk","no-reply@mywebsite.co.uk"); // Name is optional
$mail->AddTo("no-reply@mywebsite.co.uk","no-reply@mywebsite.co.uk"); // Name is optional
$mail->Subject = "Hello World Again!";
$mail->Message = "Hello World!";
//Optional
$mail->ContentType = "text/html"; // Defaults to "text/plain; charset=iso-8859-1"
$mail->Headers['X-SomeHeader'] = 'abcde'; // Set some extra headers if required
$mail->ConnectTimeout = 30; // Socket connect timeout (sec)
$mail->ResponseTimeout = 8; // CMD response timeout (sec)
$success = $mail->Send();
?>
当我对此进行测试时,会发送一封电子邮件,但当然只会发送“Hello World”文本,因为我不确定在哪里放置必要的代码来获取我需要的信息。
在移动主机并且不需要 SMTP 之前,我正在使用此脚本
<?php
//-----------------------------------------------------
//-----------------------------------------------------
$address= "myemail.co.uk";
//-----------------------------------------------------
//-----------------------------------------------------
$name = $_REQUEST["name"];
$email = $_REQUEST["email"];
$phone = $_REQUEST["phone"];
$message_content = $_REQUEST["message"];
$mime_boundary = md5(time());
$headers = "From: $name <$email>\n";
$headers .= "Reply-To: $subject <$email>\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/alternative; boundary=\"$mime_boundary\"\n";
$message = "-- $mime_boundary\n\n";
$message .= "New email from the Commons website: \n\n\n";
$message .= "Name: $name \n\n";
$message .= "Email: $email \n\n";
$message .= "Phone: $phone \n\n";
$message .= "Message: $message_content \n\n";
$message .= "--$mime_boundary--\n\n";
$mail_sent = mail($address, $subject, $message, $headers);
echo $mail_sent ? "Success, mail sent!" : "Mail failed";
?>
提前致谢
亲切的问候
提姆
【问题讨论】:
-
为什么不用php邮件功能??
-
我不确定我是否关注