Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在某些网页上发送PHP邮件_Php_Email_Gmail - Fatal编程技术网

在某些网页上发送PHP邮件

在某些网页上发送PHP邮件,php,email,gmail,Php,Email,Gmail,此代码用于我的联系人页面,它会弹出一封我可以用gmail阅读的电子邮件 <?php $message = "Sender:" . "\r\n" . $_POST["email"] . "\r\n" . "\r\n" . "Company Name:" . "\r\n" . $_POST["company"] . "\r\n" . "\r\n" .'Message:' . "\r\n" . $_POST["message"]; $to = "EMAIL ADDRESS TAKEN OUT

此代码用于我的联系人页面,它会弹出一封我可以用gmail阅读的电子邮件

<?php
$message = "Sender:" . "\r\n" . $_POST["email"] . "\r\n" . "\r\n" . "Company Name:" . "\r\n" . $_POST["company"] . "\r\n" . "\r\n" .'Message:' . "\r\n" . $_POST["message"];

$to = "EMAIL ADDRESS TAKEN OUT FOR SECURITY PURPOSES, IT'S LEGIT";
$subject = $_POST["title"];
$body = $message; 

$headers = 'From:' . $_POST["email"] . "\r\n" .
    'Reply-To:'  . $_POST["email"] . "\r\n" .
    'X-Mailer: PHP/' . phpversion();


if (mail($to, $subject, $body, $headers)) {
    echo("<p class='form'>You're message was sent successfully! We'll get back to you shortly. In the mean-time... ");
} else {
echo("<p class='form'>Oops! There was an error sending your message.");
}
?>
在冒号(“:”)后面的离子From、X-Mailer等,应该有一个空格

$headers = 'From: ' . $_POST["email"] . "\r\n" .
    'Reply-To: '  . $_POST["email"] . "\r\n" .
    'X-Mailer: PHP/' . phpversion();
此外,请确保“To”的格式正确

第二页上的
$email
的值是多少?设置是否正确


最后,这在哪台服务器上运行?是否默认的
From:
电子邮件地址无效(这就是为什么第一页上的代码按预期工作,因为它正在设置正确的
From
电子邮件地址?)。

两页上都必须存在
$email
变量,这意味着您必须以某种方式将其传输到第二个脚本,通过
$\u获取
$\u会话

在你的第一个剧本中

// put this at the very top of the script to start a session
<?php
session_start();

// then, do your stuff and, after you set your $email variable, se a session
$_SESSION['email'] = $email;
//将其放在脚本的最顶端以启动会话

第一个代码以前工作过。第二段代码存在于不同的页面上,不起作用。但是我更新了它,因为我可以。:)好啊服务器的详细信息如何?默认情况下,发件人电子邮件地址是否正确,因为第二页上没有发送标题。变量不相关,使用一次后将被丢弃。我更新了主题,以确保每个人都能看到它。谢谢你的回复。好的。你确定gmail现在不是很慢吗?您是否尝试在其他服务上使用其他电子邮件地址?
// put this at the very top of the script to start a session
<?php
session_start();

// then, do your stuff and, after you set your $email variable, se a session
$_SESSION['email'] = $email;
<?php
session_start();
$email = $_SESSION['email'];

// do your other stuff, then send your email...
mail($email, $subject, $message);