PDA

View Full Version : Configure Mail in PHP




jumpersknee
Jan 5, 2006, 10:33 PM
Anybody know how to congifure mail in
php so that it works? Running Panther and using
localhost so I can mess with my configure files.

Tried this code and nothing happens.
Thanks for the help!

<?php

//Some variables
$mymail = "jumpersknee@bis.midco.net";
$ename = $_POST['ename'];
$eemail = $_POST['eemail'];
$esubject = $_POST['esubject'];
$emessage = $_POST['emessage'];
$eip = $_POST['eip'];

//Function to check email address
function checkemail($eemail) {
if(eregi("^[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,4}$",$eemail)) {
return true;
}
else {
return false;
}
}

//Mail Processing
if ($_POST['esubmit']) {
//Check for blank fields
if ($ename == "" || $eemail == "" || $esubject == "" || $emessage == "") {
echo "<p>It appears that you left a blank field.<br/> Please make sure you fill everything in.</p>";
}
//Check to see if the email address is valid
else if (checkemail($eemail) == false) {
echo "<p>It appears that you enter an invalid email address.<br/> Please check your email again.</p>";
}
//Send the email if there's no error
else {
$body = "$emessage\n\nName: $ename\nEmail: $eemail\nIp: $eip";
mail($mymail,$esubject,$body,"From: $eemail\n");
echo "<p>Thank you for your email $ename!</p>";
}
}

?>



littlejim
Jan 8, 2006, 10:55 AM
Anybody know how to congifure mail in
php so that it works? Running Panther and using
localhost so I can mess with my configure files.

..SNIP..

?>

I didn't look too close at the code but I suspect you need to enable postfix.

The easiest way of doing this is via PostfixEnabler (http://cutedgesystems.com/software/PostfixEnabler/) if you are using Panther or MailServe (http://cutedgesystems.com/software/MailServe/index.php) for Tiger.

You can enable Postfix without spending any money but you'll have to do a reasonable amount of homework (macosxhints.com is a good starting place and Webmin (http://www.webmin.com/) is a free and fantastic tool that can help ).

One thing to look out for is the fact that a lot of ISP's will block outgoing mail from your Mac as protection against Spam - so you may need to set up Postfix to use an existing email host.

Hope this lot of waffle is of some use - I'm no expert!

Mitthrawnuruodo
Jan 8, 2006, 11:08 AM
Are you sure that the script actually gets all the way down to execute the mail() function?

Try making a very easy php script:
<?php
$mymail = "<your mail address>";
$esubject = "Test";
$body = "Body";
$eemail = "<your mail address>";
$sent = mail($mymail,$esubject,$body,"From: $eemail\n");
if ($sent) echo "Sent a mail to ".$mymail;
else echo "Couldn't send mail...?";
?>

And see if it still does nothing... :)

littlejim
Jan 8, 2006, 11:12 AM
And one other thing -

Open up 'Console' (Applications->Utilities), and examine the /var/log/mail.log file. That can give a lot of clues.