0

MacでMampを実行していて、mail()を機能させようとしています。

これは私が一緒に仕事をしなければならないものです。

$to = 'mymail@gmail.com';
$subject = 'The subject!';
$message = 'Hi there!';


$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= "X-Mailer: PHP/".phpversion();
$headers .= 'From: Test <test@test.com>' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";


// Mail it
if(mail($to, $subject, $message, $headers))
{ print 'success!'; }
else
{ print 'fail!'; }

?>

それはただfalseを返し続けます。私が間違っていることについて何か考えはありますか?php / apacheのいくつかの設定を確認する必要がありますか?

4

2 に答える 2

1

ローカルホストでスニペットを使用している場合は、サーバーに配置してから試してください。php mail() 関数を機能させるには、サーバー上にある必要があります。ローカルホストでは、常に失敗します!

于 2012-04-25T20:39:08.077 に答える
0

これを試して:

<?php
$Name = "Da Duder"; //senders name
$email = "email@adress.com"; //senders e-mail adress
$recipient = "PersonWhoGetsIt@emailadress.com"; //recipient
$mail_body = "The text for the mail..."; //mail body
$subject = "Subject for reviever"; //subject
$header = "From: ". $Name . " <" . $email . ">\r\n"; //optional headerfields

ini_set('sendmail_from', 'me@domain.com');

mail($recipient, $subject, $mail_body, $header);
?>

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

テキストの各行は 70 文字を超えてはならず、LF (\n) で区切る必要があります。

EDIT:@bradが示唆したように:SwiftMailerは本当に良いです!

于 2012-04-25T18:22:49.060 に答える