2012-10-19 55 views
0

我有一個使用SMTP認證使用梨的聯繫表。我想發送確認電子郵件給填寫表格的人。PHP SMTP郵件聯繫表格

我會得到什麼添加到我的PHP來實現這一目標

<?php 
     error_reporting(E_ALL); 
     ini_set('display_errors', True); 

     set_include_path('******'); 

     require_once "Mail.php"; 

// Set the email variables from the form here: 

    $name = $_POST['name']; // Pass the Name value to the $Name variable 
    $number = $_POST['number']; 
    $email = $_POST['email']; // Pass the Email value to the $Email variable 
    $enquiry = $_POST['enquiry']; 
    $comment = $_POST['message']; // Pass the Comment value to the $Comment variable 

$from = $email; 
$to = "Enquiries <[email protected]>"; 
$subject = "Enquiry ($enquiry)"; 

     $body = "You have received a Web Enquiry. \n 
      Name: $name\n 
      Contact: $number \n 
      Email: $email\n 
      Enquiry Type: $enquiry \n 
      Comments: $comment"; 

$host = "******.com.au"; 
$username = "*****.com.au"; 
$password = "******"; 

$headers = array('From' => $from, 
        'To' => $to, 
        'Subject' => $subject); 
$smtp = Mail::factory('smtp', 
         array('host' => $host, 
          'auth' => true, 
          'username' => $username, 
          'password' => $password)); 

$mail = $smtp->send($to, $headers, $body); 

if (PEAR::isError($mail)) { 
    echo("<p>" . $mail->getMessage() . "</p>"); 
} else { 
    echo("<p>Message successfully sent! We will be in contact with you shortly!</p>"); 
} 
?> 

感謝,

+0

是否需要確認電子郵件或電子郵件副本(如Ivan建議的)? :) –

回答

2

你可以在頭陣

'Cc' => 'Sendername <$from>', 

或前夕使用CC尤爲明顯

'Bcc' => 'Sendername <$from>', 
+1

+1但是'Bcc'更適合,對不對? :) –

+0

是的,密件是正確的事情...好地方! :) – Ivan

+0

是的,我想到了密件抄送,但我希望它與我得到的信息有點不同,但現在我想到了,兩種方式都沒有關係。 –

0

Ivan's solut如果你希望他們收到你收到的同樣的電子郵件,離子是很好的。

但最好是給他發送一封不同的電子郵件。

您生成兩個。一次給你,一次給他。

如果你想讓公共部分爲它使用一個單獨的變量,只需附加或前綴到消息。