【问题标题】:Php email send copy to senderPhp电子邮件发送副本给发件人
【发布时间】:2015-08-25 10:27:35
【问题描述】:

我有一个联系表,我正在使用下面的 PHP 脚本从我的联系表中获取电子邮件。我也想将同一电子邮件的副本发送到发件人电子邮件。谁能帮我?。谢谢!

<?php 
$errors = '';
$myemail = 'chocolatehills_adventurepark@yahoo.com, chocolatehills88@yahoo.com';//<-----Put Your email address here.
if(empty($_POST['name'])  || 
    empty($_POST['email']) || 
    empty($_POST['subject']) ||
    empty($_POST['message']))
{
    $errors .= "\n Error: all fields are required";
}

$name = $_POST['name']; 
$email_address = $_POST['email']; 
$subject = $_POST['subject']; 
$message = $_POST['message']; 

if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i", 
$email_address))
{
    $errors .= "\n Error: Invalid email address";
}

if( empty($errors))
{
    $to = $myemail; 
    $email_subject = "Message from: $name";
    $email_body = "New message received. ".
    " Here are the details:\n \n    NAME: $name \n 
    SUBJECT: $subject \n
    EMAIL ADD: $email_address \n 
    MESSAGE: $message"; 

    $headers = "From: $email_address\n"; 
    //$headers .= "Reply-To: $email_address";

    mail($to,$email_subject,$email_body,$headers);
    //redirect to the 'thank you' page
    header('Location: contact-us.php');
} 
?>

【问题讨论】:

  • 您已经发送了一封包含您的代码的电子邮件。是什么阻止您使用相同的结构发送另一个?
  • 我想给发件人发同样的邮件
  • 知道了。你还没有回答我的问题。

标签: php email copy send sender


【解决方案1】:

您也可以尝试添加其他类似这样的邮件功能

mail($email_address,$email_subject,$email_body,$headers);

【讨论】:

  • 最好在 $headers 变量中添加 cc。但如果你在现有的邮件功能下添加我的代码行,它也可以工作
【解决方案2】:

http://php.net/manual/en/function.mail.php

使用 CC 和 BCC 的示例。

示例 #4 发送 HTML 电子邮件

// Additional headers
$headers .= 'To: Mary <mary@example.com>, Kelly <kelly@example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive@example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck@example.com' . "\r\n";

【讨论】:

    【解决方案3】:

    您可以使用 cc n 标头

    $headers .= 'Cc: somebody@domain.com' . "\r\n";
    

    More idea

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-10-03
    • 2011-09-16
    • 2020-07-26
    • 1970-01-01
    • 2020-11-29
    • 1970-01-01
    • 2019-06-26
    • 1970-01-01
    相关资源
    最近更新 更多