如何使用PHP发送电子邮件?

时间:2009-06-23 12:21:32

标签: php email

  

可能重复:
  how to send email with graphic via php
  how to send mail using php?

<?php 
$error_occured = "no";
$name = $_POST['name']; 
$b_name = $_POST['b_name'];
$number = $_POST['number'];
$email_address = $_POST['email'];
$situation = $_POST['situation'];
$checkup = $_POST['brand_checkup'];
$bb_workshop = $_POST['BB'];
$recommend = $_POST['Recommend'];
$creative = $_POST['Creative_Team'];
$nominate = $_POST['Nominate']; 
$inspired = $_POST['Inspired']; 
$subject = $_POST['subject']; 

if($error_occured=="no") { 

$to = "michelle@localhost"; 
$email_from = $email_address; 
$email_subject = "New mail from www.enyeheri.com!";
$email_body = "You have received a new message. Here are the details: \n\nName:" .$name . " \n\n Business Name:" .$b_name. "\n\n Business Number: " . $number ."\n\n Email Address:" .$email_address . "\n\n Business Situation:" .$situation . "\n\n Brand Check-up: " . $checkup . "\n\n BB workshop: " .$bb_workshop . "\n\n Recommendation: " .$recommend . "\n\n Creative Team: " .$creative . "\n\n Nominate: " .$nominate . "\n\n Inspired: " .$inspired ; 
$headers = "From: $email_from"; 
mail($to,$email_subject,$email_body,$headers);
echo "Your message was sent successfully";
} 
?>

1 个答案:

答案 0 :(得分:1)

mail()

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

此函数的返回值为bool。您应该使用它来确定邮件是否已成功发送。

您可能想要查看双引号字符串和heredoc字符串:

$name = 'Benedict';

$greeting = 'Hello ' . $name . '\n Would you like a cup of tea?';
$greeting = "Hello $name \n Would you like a cup of tea?";
$greeting = <<<GREETING
Hello $name
Would you like a cup of tea?
GREETING;

所有3 $greeting都相同。