Page 1 of 2
Mail function in PHP 5.2.5
Posted: Tue Jul 15, 2008 11:53 pm
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
Re: Mail function in PHP 5.2.5
Posted: Wed Jul 16, 2008 12:09 am
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 ?
Re: Mail function in PHP 5.2.5
Posted: Wed Jul 16, 2008 12:16 am
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.
Re: Mail function in PHP 5.2.5
Posted: Wed Jul 16, 2008 12:26 am
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
Re: Mail function in PHP 5.2.5
Posted: Wed Jul 16, 2008 12:52 am
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
Re: Mail function in PHP 5.2.5
Posted: Wed Jul 16, 2008 10:25 am
by omniuni
Can you post the piece of code that does the eMailing?
Re: Mail function in PHP 5.2.5
Posted: Wed Jul 16, 2008 11:46 pm
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
Re: Mail function in PHP 5.2.5
Posted: Wed Jul 16, 2008 11:54 pm
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.)
Re: Mail function in PHP 5.2.5
Posted: Thu Jul 17, 2008 12:01 am
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..
Re: Mail function in PHP 5.2.5
Posted: Thu Jul 17, 2008 12:08 am
by vani sri
Above coding is working on php 4.4.4 but in version 5.2.5 the mail function is not working
Re: Mail function in PHP 5.2.5
Posted: Thu Jul 17, 2008 12:24 am
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...
Re: Mail function in PHP 5.2.5
Posted: Thu Jul 17, 2008 12:37 am
by vani sri
Hi..
I tried the following coding.Still the same pbm.
Code: Select all
<?php
$ok = mail("toaddress", "tttt", "message","fromaddress");
?>
Re: Mail function in PHP 5.2.5
Posted: Thu Jul 17, 2008 12:42 am
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);
?>
Re: Mail function in PHP 5.2.5
Posted: Thu Jul 17, 2008 12:52 am
by vani sri
Thanks for kindly replies.
I modified the coding as above. But i didn't get any mails.
Thanks & Regards,
vani
Re: Mail function in PHP 5.2.5
Posted: Thu Jul 17, 2008 1:04 am
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;
}
?>