PDA

View Full Version : Cách gữi mail trong php



nhockien1986
08-07-2010, 10:58
Các anh bro cho em hỏi tại sao em cài thằng smtp và cấu hình smtp rùi sao lại gữi mail ko đc, anh nào bik thì xin giúp đở e dùm,thanks!
code:
if (isset($_REQUEST['email']))
{
$email = $_REQUEST['email'] ;
$to = $_REQUEST['to'] ;
$subject = $_REQUEST['subject'] ;
$message = $_REQUEST['message'] ;
mail( $to, "Subject: $subject",$message );
echo "sendmail sucess";
}
else
{
echo "<form method='post' action='sendmail.php'>
Ngu?i g?i: <input name='email' type='text' /><br />
G?i t?i: <input name='to' type='text' /><br />
Tiêu d?: <input name='subject' type='text' /><br />
N?i dung:<br />
<textarea name='message' rows='15' cols='40'>
</textarea><br />
<input type='submit' value='Ok'/>
</form>";
}

namduong8889
08-07-2010, 12:33
nó báo lỗi gì vậy? Mà mail viết thiếu header, không có header sao gửi được.



// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// 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";

// Mail it
mail($to, $subject, $message, $headers);


Với cả $content nên wordwrap lại.



// In case any of our lines are larger than 70 characters, we should use wordwrap()
$message = wordwrap($message, 70);