mail() problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Matt Phelps
Forum Commoner
Posts: 82
Joined: Fri Jun 14, 2002 2:05 pm

mail() problem

Post by Matt Phelps »

I am dabbling with the mail() function but I don't seem to have much success. Although I think the code is correct it doesn't seem to send the mail successfully.

I have a phpNuke website also running on my host's webspace and that uses the mail() function all the time without a problem - so I know that my webhost is set up for sending mail okay.

Is there an easy way to faultfind problems with mail()?

I'm using a very simple bit of code:

Code: Select all

$mail_to ="someone@myemailaddress.com";
$mail_subject ="Does this work?";
$mail_body ="testing testing";

mail($mail_to, $mail_subject, $mail_body);
This doesn't work at all. :(
Matt Phelps
Forum Commoner
Posts: 82
Joined: Fri Jun 14, 2002 2:05 pm

Post by Matt Phelps »

Tried this code:

Code: Select all

<?php
		$email = "my@emailaddress.com";
	    $message = "message";
	    $subject = "subject line";
	    $from = "Matt Phelps";
	   if(mail($email, $subject, $message, "From: $from\nX-Mailer: PHP/" . phpversion()))
		echo "mail sent successfully";


?>
And I get the 'mail sent successfully' message but the email never arrives. (obviously I use my own email address for the $email variable.

And if you are wondering about the NX mailer bit I just took that straight from the phpNuke code because I knew it worked.

From my webhosts phpinfo.php some information which might be relevant?

sendmail_from
me@localhost.com me@localhost.com
sendmail_path
/bin/easymail -t /bin/easymail -t

Doesn't mean a hell of a lot to me but maybe to someone here?
User avatar
gite_ashish
Forum Contributor
Posts: 118
Joined: Sat Aug 31, 2002 11:38 am
Location: India

Post by gite_ashish »

hi,

if you can login (SSH, Telnet) access into u r server, try this:
tail -f /var/log/maillog
-OR-
tail -f /var/adm/maillog
execute your php mail sending script and see what log says...
Matt Phelps
Forum Commoner
Posts: 82
Joined: Fri Jun 14, 2002 2:05 pm

Post by Matt Phelps »

Unfortunately I don't have telnet access to my hosts server. :(
User avatar
gite_ashish
Forum Contributor
Posts: 118
Joined: Sat Aug 31, 2002 11:38 am
Location: India

Post by gite_ashish »

hi,

in your script put this at top and see if anything gets displayed:

Code: Select all

&lt;?php

error_reporting( E_ALL );

    //
    // your mail() code
    //

?&gt;
Matt Phelps
Forum Commoner
Posts: 82
Joined: Fri Jun 14, 2002 2:05 pm

Post by Matt Phelps »

Didn't see any error messages at all. The code simply reported that 'message sent successfully' so I can only assume that mail() is returning TRUE.

Can't understand why this works perfectly within the NUKE site I have but not in a standalone simple script like this is!
User avatar
gite_ashish
Forum Contributor
Posts: 118
Joined: Sat Aug 31, 2002 11:38 am
Location: India

Post by gite_ashish »

hi

try this script:

Code: Select all

&lt;?php

       $email      = "my@emailaddress.com"; 
       $message = "message"; 
       $subject    = "subject line"; 
       // change to email id
       $from       = "MattPhelps@emailaddress.com"; 

       if ( mail( $email, $subject, $message, "From: $from\nX-Mailer: PHP/" . phpversion() ) )
          echo "mail sent successfully"; 

?&gt;
i have only changed the $from to email id; instead of name.
Matt Phelps
Forum Commoner
Posts: 82
Joined: Fri Jun 14, 2002 2:05 pm

Post by Matt Phelps »

BINGO! It obviously insists on having a valid email address in the FROM field before it sends any mail. I guess that makes sense.

Works perfectly now! Thanks a billion! :)
Post Reply