Xavio
Xavio

Reputation: 437

Can't get php mail() to work

I've got Mamp running on my mac and trying to get mail() to work.

This is what I've got to work with.

$to = '[email protected]';
$subject = 'The subject!';
$message = 'Hi there!';


$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= "X-Mailer: PHP/".phpversion();
$headers .= 'From: Test <[email protected]>' . "\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!'; }

?>

It just keeps on returning false. Any idea what I'm doing wrong? Some settings with php/apache I need to check?

Upvotes: 0

Views: 1159

Answers (2)

m-t
m-t

Reputation: 502

if you using your snippet on localhost, put on server and then try. php mail() function needs to be on sever if you want it to work. on localhost you always get fail!

Upvotes: 1

BlueCacti
BlueCacti

Reputation: 10800

Try this:

<?php
$Name = "Da Duder"; //senders name
$email = "[email protected]"; //senders e-mail adress
$recipient = "[email protected]"; //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', '[email protected]');

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

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

each line of text may not be bigger than 70 chars and needs to be cut off with a LF (\n)

EDIT: as @brad suggested: SwiftMailer is realy good!

Upvotes: 0

Related Questions