Mail function in PHP 5.2.5

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

vani sri
Forum Commoner
Posts: 28
Joined: Fri Apr 25, 2008 12:20 am

Mail function in PHP 5.2.5

Post by vani sri »

Hi all,
i am using PHP 5.2.5 version. In this the mail function is not working. Its shows the mail send successfully. But the mail was not received.
Pls any one help me...

Regards,
vani
User avatar
omniuni
Forum Regular
Posts: 738
Joined: Tue Jul 15, 2008 10:50 pm
Location: Carolina, USA

Re: Mail function in PHP 5.2.5

Post by omniuni »

It is likely that PHP is not configured properly, but....

What sort of host is this? Have you checked your SPAM filters? Is there an active and working eMail address@thisdomain ?
vani sri
Forum Commoner
Posts: 28
Joined: Fri Apr 25, 2008 12:20 am

Re: Mail function in PHP 5.2.5

Post by vani sri »

1->Sorry i didn't get what sort of host is this?
2->Ya i checked in spam also. But i didn't received the mail
3->I checked the activation mail,It's working from address@thisdomain.
User avatar
omniuni
Forum Regular
Posts: 738
Joined: Tue Jul 15, 2008 10:50 pm
Location: Carolina, USA

Re: Mail function in PHP 5.2.5

Post by omniuni »

Oops, sorry if I wasn't clear;


Is the server in-house? Is it hosted for you somewhere? Have you sent, as well as received a mail from this server?

-Omni
vani sri
Forum Commoner
Posts: 28
Joined: Fri Apr 25, 2008 12:20 am

Re: Mail function in PHP 5.2.5

Post by vani sri »

1->The server is not in-house
2->It is hosted from 3rd party
3->yes, I received from this server

Regards,
vani
User avatar
omniuni
Forum Regular
Posts: 738
Joined: Tue Jul 15, 2008 10:50 pm
Location: Carolina, USA

Re: Mail function in PHP 5.2.5

Post by omniuni »

Can you post the piece of code that does the eMailing?
vani sri
Forum Commoner
Posts: 28
Joined: Fri Apr 25, 2008 12:20 am

Re: Mail function in PHP 5.2.5

Post by vani sri »

Code: Select all

<?
$to = "toaddress";
$subject = "Hi!";
"Hi,\n\nHow are you?";
$body = "Thanks for saying ...\r\n\n " . $comment . "\r\n\nAnd you will receive the VERY next newsletter at this email address.\r\n\n Thanks -- Mike.";
$headers = "From: fromaddress\r\n" .
"X-Mailer: php";
if (mail($to, $subject, $body, $headers)) {
echo("<p>Message sent!</p>");
} else {
echo("<p>Message delivery failed...</p>");
}
?>
This is the code
User avatar
omniuni
Forum Regular
Posts: 738
Joined: Tue Jul 15, 2008 10:50 pm
Location: Carolina, USA

Re: Mail function in PHP 5.2.5

Post by omniuni »

Try removing "$headers" from the mail function, try to send it, and let me know if it goes through. (The headers are additional, they are not required to actually send a mail.)
vani sri
Forum Commoner
Posts: 28
Joined: Fri Apr 25, 2008 12:20 am

Re: Mail function in PHP 5.2.5

Post by vani sri »

Hi,
I tried by passing from address directly,It shows msg Send. But i did not received any mail in my inbox and in spam mail..
vani sri
Forum Commoner
Posts: 28
Joined: Fri Apr 25, 2008 12:20 am

Re: Mail function in PHP 5.2.5

Post by vani sri »

Above coding is working on php 4.4.4 but in version 5.2.5 the mail function is not working
User avatar
omniuni
Forum Regular
Posts: 738
Joined: Tue Jul 15, 2008 10:50 pm
Location: Carolina, USA

Re: Mail function in PHP 5.2.5

Post by omniuni »

php5 is a little more strict. try removing line 4, (the one after $subject is declared)and make sure to start your tags with the full <?php and not just <?

let's see what that does...
vani sri
Forum Commoner
Posts: 28
Joined: Fri Apr 25, 2008 12:20 am

Re: Mail function in PHP 5.2.5

Post by vani sri »

Hi..
I tried the following coding.Still the same pbm.

Code: Select all

 
<?php
    $ok = mail("toaddress", "tttt", "message","fromaddress");
?>
 
User avatar
omniuni
Forum Regular
Posts: 738
Joined: Tue Jul 15, 2008 10:50 pm
Location: Carolina, USA

Re: Mail function in PHP 5.2.5

Post by omniuni »

Right, I think it's in the headers... try:

Code: Select all

<?php
 
$to = "YourMail@blank.com";
$subject = "test";
$message = "myMessage";
 
mail($to, $subject, $message);
 
?>
vani sri
Forum Commoner
Posts: 28
Joined: Fri Apr 25, 2008 12:20 am

Re: Mail function in PHP 5.2.5

Post by vani sri »

Thanks for kindly replies.
I modified the coding as above. But i didn't get any mails.

Thanks & Regards,
vani
User avatar
omniuni
Forum Regular
Posts: 738
Joined: Tue Jul 15, 2008 10:50 pm
Location: Carolina, USA

Re: Mail function in PHP 5.2.5

Post by omniuni »

Wow, I'm really sorry 'bout all this!

:?

I'm stumped myself, now.

It is possible that is must include a valid from, but at this point, I would contact your host directly.

For example, on my host, you have to have a valid from address that exists on the server (this helps prevent spamming from some account that they host).

I can only wish you the very best of luck, at this point. When you figure out a solution, please post it for future reference!

If I think of anything, I'll post it. As one last attempt, here is a mail form that I myself use on a PHP5 page.

Replace the "From:" line with a valid eMail address that exists on the server.

Code: Select all

<?php
 
$email = $_POST['email'];
$phone = $_POST['phone'];
$body = $_POST['body'];
$message = "eMail: ".$email."<br>Contact: ".$phone."<br>MESSAGE:<br>".$body;
if(isset($_POST['body'])){
    $headers = <<<stop_heredoc_headers
Content-type: text/html; charset=iso-8859-1
From: nobody@nowhere.com
Reply-To: $email
stop_heredoc_headers;
    $text = $message;
    $to = $settings['email'];
    $subject = "Website eMail: \"".substr($body,0,30)."...\"";
mail($to,$subject,$message,$headers);
echo "Thank You. Your Mail Has Been Sent:<br><br>".$message."<br><br><a href=\"?\">Home</a>";}else{
echo <<<END
 
            <form method="post" action="?page=contact" name="simpleSender">
What's your eMail Address?<br><input size="30" name="email" /><br><br>
What's your Phone Number?<br><input size="30" name="phone" /><br><br>
Message:<br>
<textarea cols="60" rows="6" name="body" style="width: 98%; height: 260px;"></textarea><br>
<div align="right">
<input value="Send e-mail" type="submit" />
</div>
            </form>
END;
}
?>
Post Reply