icon Get the most out of Surmunity, read our tips here! Need an interesting blog to read? You've got to read the Surpass Blog! | Welcome! Please register to access all of our features.

» Surpass Web Hosting Forums » Discussions » PHP, MySQL » Email from form sending twice

PHP, MySQL General PHP questions. Or go to our PHPsuexec Forum >>

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread
Old April 23rd, 2007, 2:52 AM   #1 (permalink)
Registered User
Fresh Surpasser
 
Joined in Mar 2005
5 posts
Gave thanks: 0
Thanked 0 times
Email from form sending twice

The following form and PHP is resulting in 2 seperate emails... one that is formatted properly with the relevant information, and a second, blank email with "Unknown Sender" as the address. Could use some help with the code:

FORM

Code:
<form method="post" action="sendemail.php">
<strong>Name:</strong> <input name="sender" type="text" style="margin-bottom: 5px;" /><br />
<strong>Subject:</strong> <input name="subject" type="text" style="margin-bottom: 5px;" /><br />
<strong>Your Email:</strong> <input name="email" type="text" style="margin-bottom: 5px;" /><br /><br />
<strong>Message:</strong><br />
<textarea name="message" rows="15" cols="40"></textarea><br />
<input type="submit" value="submit" />
</form>
PHP

Code:
<?php
	$subject = $_POST['subject'];
	$message = $_POST['message'];
	$from = "From: ".$_POST['sender']." <".$_POST['email'].">";
	$to = "xxxx@xxxx.com";
	$mail_success = mail($to, $subject, $message, $from);
	if ($mail_success == true) {
		echo '<strong>Thank you. Your email was sent successfully.</strong>';
	} else {
		echo '<strong>Error sending mail. Please try again.</strong>';
	}
?>
Also, I tried this on another host, and I could not duplicate the problem. I assume this is Surpass Hosting specific.

Last edited by M.C. McMic; April 23rd, 2007 at 2:54 AM..
M.C. McMic is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old April 23rd, 2007, 3:52 AM   #2 (permalink)
Race Surpass
Super #1
 
MarkRH's Avatar
 
Joined in Jul 2006
Lives in Oklahoma City, OK
Hosted on sh102
1,222 posts
Gave thanks: 18
Thanked 86 times
Might try the following instead:

PHP Code:
$from "From: ".$_POST['sender']." <".$_POST['email'].">\r\n";
$to "xxxx@xxxx.com";
$subject $_POST['subject'];
$message $_POST['message']."\n\n";
$headers $from;
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$mail_success mail($to$subject$message$headers);
if (
$mail_success == true) {
    echo 
'<strong>Thank you. Your email was sent successfully.</strong>';
} else {
    echo 
'<strong>Error sending mail. Please try again.</strong>';

Hopefully I didn't make a typo somewhere LOL.
MarkRH is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old April 23rd, 2007, 4:50 PM   #3 (permalink)
Registered User
Fresh Surpasser
 
Joined in Mar 2005
5 posts
Gave thanks: 0
Thanked 0 times
Quote:
Originally Posted by MarkRH View Post
Might try the following instead:

PHP Code:
$from "From: ".$_POST['sender']." <".$_POST['email'].">\r\n";
$to "xxxx@xxxx.com";
$subject $_POST['subject'];
$message $_POST['message']."\n\n";
$headers $from;
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$mail_success mail($to$subject$message$headers);
if (
$mail_success == true) {
    echo 
'<strong>Thank you. Your email was sent successfully.</strong>';
} else {
    echo 
'<strong>Error sending mail. Please try again.</strong>';

Hopefully I didn't make a typo somewhere LOL.
Thank you for the quick response. I did try out the new code. However, it did still send the 2 seperate emails (one containing no information).
M.C. McMic is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old April 26th, 2007, 7:13 AM   #4 (permalink)
Registered User
Seasoned Poster
 
Joined in May 2005
67 posts
Gave thanks: 0
Thanked 2 times
Probably not the problem, but I do recall some bug in an earlier version of PHP (Possibly 4? I don't recall) where assigning a function to a variable and then checking that variable would result in the function being called twice or something weird.

Try:
PHP Code:
if(mail($to$subjectmessage$headers)) 
Madman is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old June 4th, 2007, 1:40 AM   #5 (permalink)
Registered User
Fresh Surpasser
 
Joined in Apr 2007
7 posts
Gave thanks: 0
Thanked 0 times
Quote:
Originally Posted by MarkRH View Post
Might try the following instead:

PHP Code:
$from "From: ".$_POST['sender']." <".$_POST['email'].">\r\n";
$to "xxxx@xxxx.com";
$subject $_POST['subject'];
$message $_POST['message']."\n\n";
$headers $from;
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$mail_success mail($to$subject$message$headers);
if (
$mail_success == true) {
    echo 
'<strong>Thank you. Your email was sent successfully.</strong>';
} else {
    echo 
'<strong>Error sending mail. Please try again.</strong>';

Hopefully I didn't make a typo somewhere LOL.
thanks this helped me get my site working, probably saved some grey hairs too
__________________
sitting on SH116 : up.justadrunk.com
weazly is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

« MySQL | Copy stats »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On