2013-09-27 63 views
1

我使用下面的PHP腳本從我接觸的形式獲取電子郵件給我。我還想將同一封電子郵件的副本發送給發件人電子郵件。我怎麼能做到這一點......可以有一個人一定行添加到我的腳本做..發送電子郵件的副本發件人PHP腳本接觸

我可以分隔多個電子郵件在$ emailTo像$emailTo = '[email protected], $email';

if(!isset($hasError)) { 

    $emailFrom = '[email protected]'; 
    $emailTo = '[email protected]'; 
    $subject = 'Submitted message from '.$name; 
    $sendCopy = trim($_POST['sendCopy']); 
    $body = "Name: $name \n\nEmail: $email \n\nComments: $comments"; 
    $headers = 'From: ' .' <'.$emailFrom.'>' . "\r\n" . 'Reply-To: ' . $email; 

    mail($emailTo, $subject, $body, $headers); 

    // set our boolean completion value to TRUE 
    $emailSent = true; 
} 

附加其它功能可能會奏效。但我在尋找一些其他簡單的方法是,在同樣的功能:)

PS:我想一個aditional的行添加到像發件人「的消息的電子郵件副本,你發送給XXX所有者」

+1

內置的PHP' mail()'功能嚴重缺乏功能,加上安全性通常在您開始編寫自己的郵件標題(您的代碼可能很容易被黑客發送垃圾郵件)時就成了問題。因此,我強烈建議在編寫PHP程序發送電子郵件時使用像PHPMailer或Swiftmailer這樣體面的郵件類。 – Spudley

+0

@Spudley謝謝你的建議。我會研究這個! – BlackCoder

回答

1

php.net/mail例如#4如何擴展$additional_headers參數添加CC收件人:

$headers = 'From: ' .' <'.$emailFrom.'>' . "\r\n" . 'Reply-To: ' . $email . "\r\n" . 'Cc: ' .' <[email protected]>';

0

您可以通過編寫

$emailTo = '[email protected], [email protected]'; 
+0

,我想發送一些額外的行給發件人。喜歡你的電子郵件副本什麼的..... – BlackCoder

+1

在這種情況下,你需要發送兩個獨立的郵件,從而調用郵件()兩次 – Reeno

-2

做到這一點你可以嘗試這樣的抄送副本發送給發送者電子郵件

$headers["From"] = "$from"; 
$headers["To"] = "$email"; 
$headers["Subject"] = $subject; 
$headers['Cc'] = '$from'; 
+0

郵件()預計字符串,而不是一個數組,對於其他參數 – Reeno

+0

概念對,但代碼不是你需要附加的,看看Alma Do Mundo的答案 – Edward

0

希望這有助於

<?php 
      $name = $_POST['name']; 
      $email_address = $_POST['email']; 
      $phone = $_POST['phone']; 
      $course = $_POST['course']; 

// Create the email and send the message 

      $to = $email_address; //This is the email address of the person who filled the form, this email will be supplied by the sender. 

      $email_subject = "Website Contact Form: $name"; 

      $email_body = "You have received a new message from your Website contact form.\n\n"."Here are the details:\n\n 
      Name: $name\n\n 
      Email: $email_address\n\n 
      Phone: $phone\n\n 
      Course:\n$course"; 

      $headers = "From: [email protected]\n"; // This is the email address the generated message will be from. We recommend using something like [email protected] 

      $headers .= 'Cc: [email protected]' . "\r\n"; // Add your email address replacing [email protected] - This is where the form will send the message to. 

      $headers .= "Reply-To: $email_address"; 

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

      return true;    
?>