Configure Mail in PHP

Discussion in 'Web Design and Development' started by jumpersknee, Jan 5, 2006.

  1. jumpersknee macrumors newbie

    Jan 5, 2006
    North Dakota
    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!


    //Some variables
    $mymail = "";
    $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>";

  2. littlejim Guest

    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 if you are using Panther or MailServe for Tiger.

    You can enable Postfix without spending any money but you'll have to do a reasonable amount of homework ( is a good starting place and Webmin 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!
  3. Mitthrawnuruodo Moderator emeritus


    Mar 10, 2004
    Bergen, Norway
    Are you sure that the script actually gets all the way down to execute the mail() function?

    Try making a very easy php script:
    $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... :)
  4. littlejim Guest

    And one other thing -

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

Share This Page