我想在我的网站上更改权限时向用户发送电子邮件,但是当我为'from'
mail()
指定header
值时,您可以看到emailing.php
文件中的'My Name at MySite.net'
文件是'My.Name.at.MySite.net@netsolhost.com'
,它会播放,并在电子邮件中显示为My Name at MySite.net
(我的主机显然是网络解决方案)。
我希望这样做,当收件箱中的电子邮件出现时,它首先显示myemail@gmail.com
和主题,但是当我点击它然后回复时,它会将回复发送到<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<?php
if (isLoggedIn()) {
if ($_SESSION['privileges'] >= 5 && isset($_GET['user_id']) && isset($_GET['new_privileges'])) {
require_once 'connect-database.php';
require_once 'database-functions.php';
if ($_GET['new_privileges'] == detail($connection, 'privileges', 'id', $_GET['user_id'])) {
$update_status = 'There is no point in changing this user\'s privileges to what they already are!';
$email_status = 'Email was not sent.';
} else if ($_GET['new_privileges'] < detail($connection, 'privileges', 'id', $_GET['user_id'])) {
$update_status = update($connection, 'privileges', $_GET['new_privileges'], 'id', $_GET['user_id']);
if ($update_status) {
$update_status = 'User\'s privileges have been updated!';
/* I HAVE THE CONTENTS OF THIS FILE BELOW THIS FILE */
require_once '../../emailing/emailing.php';
$recipient = detail($connection, 'email', 'id', $_GET['user_id']);
$message = '<p>Dear '.detail($connection, 'name', 'id', $_GET['user_id']).',<br><br>I am sorry to tell you that your privileges on MySite.net have been dropped :( If you don\'t know why this has been done, you can send me an email from the <a href="http://mysite.net/email" target="_blank">MySite.net email form</a>.</p><a href="http://mysite.net/home" target="_blank" style="text-decoration: none;"><div style="background-color: '.$theme_color.'; display: inline-block; margin: 0px auto; position: relative; border-radius: 5px; border: 0px; padding: 10px; text-decoration: none; color: white;">Visit MySite.net >></div></a><p>Best,<br>My Name</p><br>';
$email_status = sendEmail('My Name at MySite.net', 'myemail@gmail.com', $recipient, 'Your privileges have been dropped on MySite.net', $message, true);
if ($email_status) {
$email_status = 'User was notified of their change in privileges.';
} else {
$email_status = 'There was an error notifying user of their privilege change.';
}
} else {
$update_status = 'There was an error trying to update user\'s privileges.';
$email_status = 'Email was not sent.';
}
} else {
$update_status = update($connection, 'privileges', $_GET['new_privileges'], 'id', $_GET['user_id']);
if ($update_status) {
$update_status = 'User\'s privileges have been updated!';
/* I HAVE THE CONTENTS OF THIS FILE BELOW THIS FILE */
require_once '../../emailing/emailing.php';
$recipient = detail($connection, 'email', 'id', $_GET['user_id']);
$message = '<p>Dear '.detail($connection, 'name', 'id', $_GET['user_id']).',<br><br>I am happy to tell you that your privileges on MySite.net have been raised! Discover what has been revealed to you!</p><a href="http://mysite.net/home" target="_blank" style="text-decoration: none;"><div style="background-color: '.$theme_color.'; display: inline-block; margin: 0px auto; position: relative; border-radius: 5px; border: 0px; padding: 10px; text-decoration: none; color: white;">Visit MySite.net >></div></a><p>Best,<br>My Name</p><br>';
$email_status = sendEmail('My Name at MySite.net', 'myemail@gmail.com', $recipient, 'Your privileges have been raised on MySite.net!', $message, true);
if ($email_status) {
$email_status = 'User was notified of their change in privileges.';
} else {
$email_status = 'There was an error notifying user of their privilege change.';
}
} else {
$update_status = 'There was an error trying to update user\'s privileges.';
$email_status = 'Email was not sent.';
}
}
require_once 'disconnect-database.php';
} else {
header('Location: /home');
}
} else {
header('Location: /login');
}
?>
<title>Change User Privileges | MySite.net</title>
</head>
<body>
<h1>Change User Privileges</h1>
<div class="break"></div>
<p>Update Status: <?php echo $update_status; ?></p>
<p>Email Status: <?php echo $email_status; ?></p>
</body>
</html>
。我尝试了几个不同的标题,但没有任何效果。也许它与网络解决方案有关,但如果它是一个编程答案,我会感激任何帮助......如果这是问题,我仍然感谢网络解决方案的帮助!
变化-用户privileges.php:
<?php
function sendEmail($sender_name, $sender_email, $mail_to, $subject, $message, $html_format) {
// VARIABLES
$headers = 'From: '.$sender_name."\r\n";
$headers .= 'Reply-To: '.$sender_email."\r\n";
if ($html_format === true) {
$headers .= "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
/* I'VE TRIED USING THE BELOW HEADER, INSTEAD OF THE LINE ABOVE, BUT IT ALSO DOESN'T WORK */
/*$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";*/
}
// SEND EMAIL
$mail_status = mail($mail_to, $subject, $message, $headers);
return ($mail_status) ? true : false;
}
?>
以下是&#39; emailing.php&#39;:
的内容{{1}}
希望这是回答这个问题的足够信息。
答案 0 :(得分:2)
尝试:
$headers = "From: $sender_name <$sender_email>\r\n";
您的From:
标头不包含地址,只包含名称。
如果地址与Reply-to:
中的地址相同,则不需要From:
标题。