Re: mail() function failure

From: Date: Mon, 11 Aug 2003 07:54:49 +0000
Subject: Re: mail() function failure
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-159112@lists.php.net to get a copy of this message
"Brad Esclavon" <gtg724h@mail.gatech.edu> wrote in message news:20030807151933.70898.qmail@pb1.pair.com... > I have made a simple script to mail an email to a person on my domain. i > have tested the script with different values and i still cannot get the > email. when i execute the mail function, it returns true, so i know it gets > to the mail server, but the mail server doesnt actually send it. i am being > hosted by a company and am sure the mail server is up and working for me. is > there a way i need to feed it a username/password with php? any ideas on why > its not working? im completely stumped. > > <?php > > ini_set("SMTP","smtp-relay.affinity.com"); > > $mail_to = "webmaster@somewhere.com"; > $mail_from = "besc@somewhere.com"; > $mail_subject = "php mail test"; > $mail_body = "test"; > > if ( mail($mail_to, $mail_subject, $mail_body)) > {echo("sucess");} > else > {echo("fail");} > > ?> Brad, you're missing a buch of headers probably causing your email to be dropped somewhere regarded spam (especially Hotmail is quite picky about the headers). Try and send these headers (fourth argument in mail() function. $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: text/plain; charset=iso-8859-1\r\n"; $headers .= "X-Priority: 3\r\n"; $headers .= "X-MSMail-Priority: Normal\r\n"; $headers .= "X-Mailer: PHP/".phpversion()."\r\n"; //I use this, I'm not sure if you really need this header $headers .= "From: besc@somewhere.com\r\n"; $headers .= "Reply-to: besc@somewhere.com\r\n"; $headers .= "Return-path: besc@somewhere.com\r\n"; $headers .= "Error-to: besc@somewhere.com\r\n"; if (mail($mail_to, $mail_subject, $mail_body,$headers)) { echo ("success"); } else { echo ("failed"); } HTH, -- Ivo Fokkema PHP & MySQL programmer Leiden University Medical Centre Netherlands

« previous php.general (#159112) next »