PHP的邮件()使用的PhoneGap和Ajax时,不发送头 [英] php mail() not sending headers when using phonegap and ajax

查看:102
本文介绍了PHP的邮件()使用的PhoneGap和Ajax时,不发送头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很奇怪的问题发送电子邮件时。这也可能是一件很简单的修复,但我找不到任何答案在网上。

I have a very strange problem when sending emails. It's probably something very simple to fix but I can't find any answers online.

我在我的jQuery Mobile的PhoneGap的应用Ajax是(简体):

My ajax in my JQuery Mobile Phonegap application is (simplified):

$.ajax({
    url: 'http://mysite.com/ajax/app/email.php',
    type: "POST",
    dataType: "text",
    data: {
        email: $('#email').val(),
    },
    success: function(data) {
        alert('done!')
    }
});

在code。在我的email.php文件(再次,简化的):

The code in my email.php file is (again, simplified):

<?php
$email = $_POST['email'];
$headers = 'From: MySite <admin@mysite.com>' . "\r\n" .
    'Reply-To: MySite <admin@mysite.com>' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();
$msg = "Welcome to MySite!";
@mail($email, 'Hello', $msg, $headers);

电子邮件来通过罚款,但不是从admin@mysite.com是它从myaccount@web54.justhost.com。该邮件来自正确的邮箱地址,当我运行存储在同一个服务器作为email.php脚本上一个HTML5应用程序相同的AJAX查询。

The email comes through fine, but instead of being from admin@mysite.com it's from myaccount@web54.justhost.com. The email comes from the correct email address when I run the same ajax query from an HTML5 app stored on the same server as the email.php script.

任何想法?我已经列入白名单MYSERVER +所有子 - 我想不出自己还能做些什么。

Any ideas? I have whitelisted myserver + all subdomains - I can't think what else to do.

推荐答案

试图通过第五个参数传递您的电子邮件地址与 -f 标志的电子邮件()。这将有助于MTA知道的信封发件人使用的地址。

Try passing your email address with the -f flag through the fifth parameter to mail(). This will help the MTA know which address to use as the envelope sender.

看是否有此code工作:

See if this code works:

mail($email, 'Hello', $msg, $headers, '-fadmin@mysite.com');

请参考上面的信息,PHP mail()函数的邮件链接,还可以搜索 -f 上的从进出口文档的进出口命令行

您需要禁用的safe_mode 如果在你的PHP版本启用。

You will need to disable safe_mode if it is enabled in your PHP version.

这篇关于PHP的邮件()使用的PhoneGap和Ajax时,不发送头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆