homepage Welcome to WebmasterWorld Guest from 54.166.108.167
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
send mail - two email - one good, one empty
Problem with PHP send mail
purmar




msg:4458226
 7:22 pm on May 26, 2012 (gmt 0)

Hello!

I have limited PHP experience not going over arrays, include, and some basis stuff. I have been testing and testing for ever this script and have no idea why it sends regular email together with another one empty. Any idea?

<?
$name = $_POST['name'] ;
$email = $_POST['email'] ;
$phone = $_POST['phone'] ;
$subject = $_POST['subject'] ;
$message = $_POST['message'] ;

$main = 'From: ' . $name . ' ('. $email .')<br>' . $phone . '<br>' . $subject . '<br>';

$main .= '<br>';
$main .= 'Message: ' . $message . '<br>';
$main .= '<br>';

$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From:'. $email . "\r\n" ;

mail('info@company.com', 'From website', $main, $headers); //mail command :)
?>


I get this:

From: mark p (test@test.com)
1231231234
General Inquiry

Message: 3.12 time


and this :

From: ()



Message:


Could ANYBODY tell me how to stop the stupid second empty email or why this is happening?

Thank you

 

CoursesWeb




msg:4458295
 5:29 am on May 27, 2012 (gmt 0)

Hi
The cause of the seccond email, empty, can be because that page is accessed again by google bot, but without POST data.
To solve it, try this, to send mail only if valid data from POST:

if(isset($_POST['name']) && strlen($_POST['name'])>1} {
$name = $_POST['name'] ;
$email = $_POST['email'] ;
$phone = $_POST['phone'] ;
$subject = $_POST['subject'] ;
$message = $_POST['message'] ;

$main = 'From: ' . $name . ' ('. $email .')<br>' . $phone . '<br>' .$subject . '<br>';

$main .= '<br>';
$main .= 'Message: ' . $message . '<br>';
$main .= '<br>';

$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From:'. $email . "\r\n" ;

mail('info@company.com', 'From website', $main, $headers);
}

purmar




msg:4458615
 1:39 pm on May 28, 2012 (gmt 0)

Great, thanks. That seems to fixed the issue.

I was thinking that it may be the issue of somebody accessing the page directly, though the email was usually always sent together with the "real" one....

In any case I have not received any empty email for 2 days now!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved