PHP邮件()联系,我们如果进入Gmail发送地址的形式工作正常,但不能与雅虎
我设置使用的Prestashop电子商务网站和测试他们的联系表格的时候,我发现我并没有收到是否有信息用户输入Yahoo电子邮件地址作为发件人地址。但是,如果用户输入Gmail地址,我没有任何问题。PHP邮件()联系,我们如果进入Gmail发送地址的形式工作正常,但不能与雅虎
的Prestashop设置目前使用PHP邮件()函数用于接触形式。可能是什么问题,我可以看到什么解决方案,因为我显然需要接收来自所有人的邮件,而不仅仅是那些使用Gmail地址的邮件。
以下是在接触form.php的页面的代码: -
<?php
$useSSL = true;
include(dirname(__FILE__).'/config/config.inc.php');
include(dirname(__FILE__).'/header.php');
$errors = array();
$smarty->assign('contacts', Contact::getContacts(intval($cookie->id_lang)));
if (Tools::isSubmit('submitMessage'))
{
if (!($from = Tools::getValue('from')) OR !Validate::isEmail($from))
$errors[] = Tools::displayError('invalid e-mail address');
elseif (!($message = nl2br2(Tools::getValue('message'))))
$errors[] = Tools::displayError('message cannot be blank');
elseif (!Validate::isMessage($message))
$errors[] = Tools::displayError('invalid message');
elseif (!($id_contact = intval(Tools::getValue('id_contact'))) OR !(Validate::isLoadedObject($contact = new Contact(intval($id_contact), intval($cookie->id_lang)))))
$errors[] = Tools::displayError('please select a contact in the list');
else
{
if (intval($cookie->id_customer))
$customer = new Customer(intval($cookie->id_customer));
if (Mail::Send(intval($cookie->id_lang), 'contact', 'Message from contact form', array('{email}' => $_POST['from'], '{message}' => stripslashes($message)), $contact->email, $contact->name, $from, (intval($cookie->id_customer) ? $customer->firstname.' '.$customer->lastname : $from)))
$smarty->assign('confirmation', 1);
else
$errors[] = Tools::displayError('an error occurred while sending message');
}
}
$email = Tools::safeOutput(Tools::getValue('from', ((isset($cookie) AND isset($cookie->email) AND Validate::isEmail($cookie->email)) ? $cookie->email : '')));
$smarty->assign(array(
'errors' => $errors,
'email' => $email
));
$smarty->display(_PS_THEME_DIR_.'contact-form.tpl');
include(dirname(__FILE__).'/footer.php');
?>
UPDATE:
我联系,我的电子邮件托管公司,他们给出了以下建议: -
您需要将字段$ from中的电子邮件地址 更改为任何 在 上的域名上的电子邮件地址,你正在合并这个 脚本。例如,如果您的域名 名称是abc.com,那么就需要定义 发件人的电子邮件地址作为 [email protected]。此电子邮件地址 不必存在于邮箱 服务器的abc.com,但域名 名称中的$ from字段必须是您的 。您可以使用电子邮件地址 ,如[email protected]。
在$邮寄地址字段中的值需要 改变的电子邮件地址, 在需要 交付包含通过表单提交的数据 电子邮件。
因此,在Prestashop的contact-form.php(上面给出的代码)的情况下,我将如何去改变它?
不能使用未绑定到服务器,发件人地址的地址。这将被每个自尊的垃圾邮件阻止机制阻止。它实际上是一个奇迹,它的工作原理与Gmail的电子邮件地址。
如果你希望能够直接回复,人们通过您的联系方式发送给您的邮件,下面的头添加到第4个参数,以您的mail()
电话:
reply-to: customers_email_address
但作为物理发件人地址,总是使用
from: [email protected]
我的电子邮件托管公司也说过同样的事情。但在上面给出的contact-form.php代码的上下文中,我需要做什么。下一步会是什么? – nitbuntu 2010-01-26 23:25:35
我不知道,因为我无法确定邮件在代码中的发送位置。抱歉。在Prestashop的配置中应该有一个“发送电子邮件”部分。在哪一点插入标题,有人更熟悉该商店将不得不回答。 – 2010-01-27 10:33:24
有可以提供给mail()
呼叫的第五个参数。
这是我用来修复我的Drupal邮件(简体):
return @mail($message['to'],
$message['subject'],
$message['body'],
join("\n", $mimeheaders),
'-f' . $message['from']);
由于AlexV正确地指出,使用转义值是危险的,这是完整版。请注意,它是从drupal源代码中获得的(有一个小修补程序)。
function drupal_mail_wrapper($message)
{
$mimeheaders = array();
foreach ($message['headers'] as $name => $value)
{
$mimeheaders[] = $name .': '. mime_header_encode($value);
}
return @mail(
$message['to'],
mime_header_encode($message['subject']),
// Note: e-mail uses CRLF for line-endings, but PHP's API requires LF.
// They will appear correctly in the actual e-mail that is sent.
str_replace("\r", '', $message['body']),
// For headers, PHP's API suggests that we use CRLF normally,
// but some MTAs incorrecly replace LF with CRLF. See #234403.
join("\n", $mimeheaders),
($message['from'] ? '-f' . $message['from'] : ''));
}
希望帮助,克里斯
我一直在使用这个小代码发送电子邮件,在我自己的通讯系统。这段摘录专门处理单个消息。它基于RFC规范。
/**
* @package jaMailBroadcast
* @author Joel A. Villarreal Bertoldi (design at joelalejandro.com)
*
* @usage
*
* $msg = new jaMailBroadcast_Message("My Website", "[email protected]");
* $msg->to = new jaMailBroadcast_Contact("John Doe", "[email protected]");
* $msg->subject = "Something";
* $msg->body = "Your message here. You <b>can use</b> HTML.";
* $msg->send();
**/
class jaMailBroadcast_Contact
{
public $id;
public $name;
public $email;
function __construct($contactName, $contactEmail, $contactId = "")
{
$this->name = $contactName;
$this->email = $contactEmail;
if (!$contactId)
$this->id = uniqid("contact_");
else
$this->id = $contactId;
}
function __toString()
{
return json_encode
(
array
(
"id" => $this->id,
"name" => $this->name,
"email" => $this->email
)
);
}
function rfc882_header()
{
return sprintf('"%s" ', $this->name, $this->email);
}
}
class jaMailBroadcast_Message
{
public $from;
public $to;
public $subject;
public $body;
public $mime_boundary;
public $headerTemplate;
public $footerTemplate;
function __construct($fromName, $fromEmail)
{
$this->from = new jaMailBroadcast_Contact($fromName, $fromEmail);
$this->mime_boundary = "==" . md5(time());
}
private function mail_headers($EOL = "\n")
{
$headers
= "From: " . $this->from->rfc882_header() . $EOL
. "Reply-To: from->email . ">" . $EOL
. "Return-Path: from->email . ">" . $EOL
. "MIME-Version: 1.0" . $EOL
. "Content-Type: multipart/alternative; boundary=\"{$this->mime_boundary}\"" . $EOL
. "User-Agent: jaMailBroadcast/1.0" . $EOL
. "X-Priority: 3 (Normal)" . $EOL
. "Importance: Normal" . $EOL
. "X-Mailer: jaMailBroadcast";
return $headers;
}
private function rfc882_body_format($EOL = "\r\n")
{
return wordwrap($this->body, 70, $EOL);
}
function send()
{
$EOL =
(
stripos($this->to->email, "hotmail") !== false
||
stripos($this->to->email, "live") !== false
)
? "\n"
: "\n";
return mail
(
$this->to->rfc882_header(),
$this->subject,
$this->multipart_alternative_body($EOL),
$this->mail_headers($EOL),
"-f" . $this->from->email
);
}
private function multipart_alternative_body($EOL = "\r\n")
{
$multipart
= "Content-Transfer-Encoding: 7bit" . $EOL
. "This is a multi-part message in MIME format. This part of the E-mail should never be seen. If you are reading this, consider upgrading your e-mail client to a MIME-compatible client." . $EOL . $EOL
= "--{$this->mime_boundary}" . $EOL
. "Content-Type: text/plain; charset=iso-8859-1" . $EOL
. "Content-Transfer-Encoding: 7bit" . $EOL . $EOL
. strip_tags($this->br2nl($this->headerTemplate)) . $EOL . $EOL
. strip_tags($this->br2nl($this->body)) . $EOL . $EOL
. strip_tags($this->br2nl($this->footerTemplate)) . $EOL . $EOL
. "--{$this->mime_boundary}" . $EOL
. "Content-Type: text/html; charset=iso-8859-1" . $EOL
. "Content-Transfer-Encoding: 7bit" . $EOL . $EOL
. $this->headerTemplate . $EOL
. $this->body . $EOL
. $this->footerTemplate . $EOL
. "--{$this->mime_boundary}--" . $EOL;
return $multipart;
}
private function br2nl($text, $EOL = "\n")
{
$text = str_ireplace("<br>", $EOL, $text);
$text = str_ireplace("<br />", $EOL, $text);
return $text;
}
}
我将'从'更改为$_REQUEST['from']
。您也可以更改它$_POST['from']
。用此替换2',然后将$contact->email
更改为您想要发送该电子邮件的任何需要的电子邮件。
它为我工作。
例如,如果您在邮件内容中使用CRLF(\ r \ n),可能会使某些邮件服务器失效。 \ r \ n应仅用作电子邮件标题的“分隔符”,\ n作为邮件正文(内容)中的新行字符。 – AlexV 2010-01-25 15:58:57
Prestashop中的'发送电子邮件到'配置只能提供PHP邮件()函数或SMTP选项。 – nitbuntu 2010-01-25 16:07:07
你如何“喂食”发送给Prestashop的东西(我不知道这个应用程序)。 – AlexV 2010-01-25 18:07:07