【问题标题】:SMTP php mail sending code [duplicate]SMTP php邮件发送代码[重复]
【发布时间】:2015-09-21 13:04:27
【问题描述】:

我的 php 代码是这样的:

$email_message .= "Full Name: ".clean_string($full_name)."\r\n";
$email_message .= "Email: ".clean_string($email_from)."\r\n";
$email_message .= "Telephone: ".clean_string($telephone)."\r\n";
$email_message .= "Message: ".clean_string($comments)."\r\n";

$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($email_to, $email_subject, $email_message, $headers);
header("Location: $thankyou");
?>
<script>location.replace('<?php echo $thankyou;?>')</script>
<?php
}
die();
?>

这就像一个反馈表。我从访客那里得到姓名、电子邮件、电话和信息。然后我使用 php mail() 函数将这些详细信息发送到我的电子邮件。($email_to 变量在我与此文件集成的另一个文件中)。当我尝试填写表格并发送时,邮件没有到达我的 ID。然后我听说了用于发送电子邮件的 SMTP。

但我不知道如何在此编码中集成 SMTP(我的 ID 在 GMail 中。所以 smtp.gmail.com)。帮助表示赞赏

【问题讨论】:

  • 默认情况下,Gmail 不允许您向自己发送电子邮件 – specifically:“为防止混乱,Gmail 不会将您发送到自己别名的邮件路由到收件箱。”跨度>

标签: php forms email smtp gmail


【解决方案1】:

只是猜测,但您在 SMTP 中颠倒了字母.. (smtp.gmail.com

看看这个: Send email using the GMail SMTP server from a PHP page

从答案中复制:

// Pear Mail Library
require_once "Mail.php";

$from = '<from.gmail.com>';
$to = '<to.yahoo.com>';
$subject = 'Hi!';
$body = "Hi,\n\nHow are you?";

$headers = array(
    'From' => $from,
    'To' => $to,
    'Subject' => $subject
);

$smtp = Mail::factory('smtp', array(
        'host' => 'ssl://smtp.gmail.com',
        'port' => '465',
        'auth' => true,
        'username' => 'johndoe@gmail.com',
        'password' => 'passwordxxx'
    ));

$mail = $smtp->send($to, $headers, $body);

if (PEAR::isError($mail)) {
    echo('<p>' . $mail->getMessage() . '</p>');
} else {
    echo('<p>Message successfully sent!</p>');
}

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2013-09-19
  • 2017-01-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多