使用SMTP从HTML表单获取信息的PHP邮件

使用SMTP从HTML表单获取信息的PHP邮件,php,email,smtp,Php,Email,Smtp,我最近移动了主机,现在使用联系人表单,我必须使用SMTP。我已经能够在一些帮助下获得一些工作,但无法从表单中检索到我需要的信息。我试图获取的信息是姓名、电子邮件、电话和信息。这就是我一直在用的 <?php require "email.php"; $mail = new EMail; $mail->Username = 'username.co.uk'; $mail->Password = 'mypassword'; $mail->SetFrom("no-reply

我最近移动了主机,现在使用联系人表单,我必须使用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";
?>

提前谢谢

问候


蒂姆,你试过这样做吗

 $message_str = str_replace("[first_name]", $fname, $message_str);
                            $message_str = str_replace("[last_name]", $lname, $message_str);
                            $message_str = str_replace("[site_name]", "RMS", $message_str);

// Always set content-type when sending HTML email
                            $headers = "MIME-Version: 1.0" . "\r\n";
                            $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

// More headers
                            $headers .= 'From: <norply@rms.com>' . "\r\n";


                            $subject = "activate account!";
                            if (mail("asd@sad.com", $subject, $message_str, $headers)) {
                                echo"Email successfully sent!";
                            } else {
                                echo"Email delivery failed…";
                            }
$message\u str=str\u replace(“[first\u name]”,$fname,$message\u str);
$message\u str=str\u replace(“[姓氏]”,$lname,$message\u str);
$message\u str=str\u replace(“[站点名称]”、“RMS”、$message\u str);
//发送HTML电子邮件时始终设置内容类型
$headers=“MIME版本:1.0”。“\r\n”;
$headers.=“内容类型:text/html;字符集=UTF-8”。“\r\n”;
//更多标题
$headers.='From:'。“\r\n”;
$subject=“激活帐户!”;
如果(邮件)asd@sad.com“,$subject,$message_str,$headers)){
回显“电子邮件已成功发送!”;
}否则{
回显“电子邮件发送失败…”;
}

只需使用Php邮件功能

考虑下面的代码

$subject = 'Welcome To demo.com';

    $mydata['name'] = 'demo';
    $mydata['user_name'] = 'test1';
    $mydata['email'] = test@gmail.com;
    $mydata['password'] = $password;
    $mydata = (object)$mydata;
                $message = "<div style='height: 500px; background: none repeat scroll 0% 0% rgb(241, 241, 241); border: 1px solid rgb(6, 106, 117); width: 450px;'>
                <div style='width: 100%; background: none repeat scroll 0% 0% rgb(6, 106, 117); height: 80px;'>
                <div style='width:150px; height:100px;margin:8px; float:left'>
                </div>
                </div>
                  <div style='width:100%;height:360px; margin: auto; float:left; text-align: center;'>
                  <h2>Hello $mydata->name </h2>

                  <h3>Here is you login details for Demo</h3>
                  <br>
                  <h3>Username: $mydata->user_name</h3>

                  <h3>Password: $mydata->password</h3>
                  </div>
                  <div style='height:30px;padding-top:10px;float:left; width:100%;text-align:center;background:#1d5770;'>
                    <span style='color:#fff;font-weight:bold'>demo Team</span>
                  </div>
                </div>";
    //$message = "<br><br>Username:$mydata->user_name <br><br><br>Password:$mydata->password <br>";

    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    $headers .= "To: $mydata->name <$mydata->email>" . "\r\n";
    $headers .= "From: demo.com <contact@demo.com>" . "\r\n";

    mail($mydata->email, $subject, $message, $headers);

我用了这个,但是我得到的信息是电子邮件失败了

<?php

require "email.php";

$mail = new EMail;
$mail->Username = 'myemail.co.uk';
$mail->Password = 'password';

$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";

echo $mail_sent ? "Success, mail   sent!" : "Mail failed";

?>


为什么不使用php邮件功能?我不确定我是否遵循Hi Arham我是否可以在上面添加我的SMTP登录信息?Hi Arham我使用了下面的代码,该代码将提供我需要的信息,但它没有发送。我遗漏了什么吗?你把收件人的邮件id传给我了吗asd@sad.com?
<?php

require "email.php";

$mail = new EMail;
$mail->Username = 'myemail.co.uk';
$mail->Password = 'password';

$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";

echo $mail_sent ? "Success, mail   sent!" : "Mail failed";

?>