我最近移動了主機,現在使用聯繫表單我必須使用SMTP。我已經有一些幫助能夠找到工作,但無法從表單中檢索我需要的信息。我試圖拉的信息是姓名電子郵件電話和消息。這是我一直在使用PHP郵件使用SMTP從HTML表格獲取信息
<?php
require "email.php";
$mail = new EMail;
$mail->Username = 'username.co.uk';
$mail->Password = 'mypassword';
$mail->SetFrom("[email protected]","[email protected]"); // Name is optional
$mail->AddTo("[email protected]","[email protected]"); // 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郵件功能? – Aksh 2014-09-03 07:25:33
我不確定我是否遵循 – Timmer 2014-09-03 10:26:04