Forum Moderators: coopster

Message Too Old, No Replies

webforms send two emails!

i have a php script that works but send two emails

         

keentolearn

10:31 am on Mar 18, 2005 (gmt 0)

10+ Year Member



Hi all

i have hacked about abit of php to create some code that send an email from a webform. Im very new to php, but im getting two emails - one blank and one correct.

can anyone look at the below code and let me know where ive gone wrong?

<?

$title = $_REQUEST['title'] ;

$firstname = $_REQUEST['firstname'] ;

$surname = $_REQUEST['surname'] ;

$address = $_REQUEST['address'] ;

$email = $_REQUEST['email'] ;

$phone = $_REQUEST['phone'] ;

$foundsiteby = $_REQUEST['foundsiteby'] ;

$brochure = $_REQUEST['brochure'] ;

$homedemo = $_REQUEST['homedemo'] ;

$callback = $_REQUEST['callback'] ;


mail( "me@domain.com", "WebSite Feedback",
$message, "From: $email", "-fuser@me@domain.com" );
header( "Location: [domain.com...] );

$recipient = "me@domain.com";

$subject = "WebSite Feedback";

$message = "

$title

$firstname

$surname

$address

$email

$phone

$foundsiteby

$brochure

$homedemo

$callback

";

$extra = "From: $email";

mail ($recipient, $subject, $message, $extra, "-f me@domain.com
");

?>

Many thanks
Keen to learn..

dreamcatcher

11:20 am on Mar 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi,

As far as I can see your first mail function is being called BEFORE your $message variable. The second one has a $message variable before and should be ok. Try putting the mail functions together after the $message variable has been assigned.

dc

saoi_jp

1:53 pm on Mar 18, 2005 (gmt 0)

10+ Year Member



mail() sends mail. You have mail() twice, so you're sending two mails.

dreamcatcher

3:05 pm on Mar 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



LOL! I was thinking that you wanted the two e-mails. As saoi_jp mentioned, if you only want the one, remove the first mail() function.

keentolearn

7:45 am on Mar 20, 2005 (gmt 0)

10+ Year Member



Hi All

First sorry for not getting back to you for the help on this - ive been away for a few days.

as you can tell im 'very' new to this so thanks.

i have edited it as per below - does that look like it will work now?

<?

$title = $_REQUEST['title'] ;

$firstname = $_REQUEST['firstname'] ;

$surname = $_REQUEST['surname'] ;

$address = $_REQUEST['address'] ;

$email = $_REQUEST['email'] ;

$phone = $_REQUEST['phone'] ;

$foundsiteby = $_REQUEST['foundsiteby'] ;

$brochure = $_REQUEST['brochure'] ;

$homedemo = $_REQUEST['homedemo'] ;

$callback = $_REQUEST['callback'] ;

$recipient = "me@domain.com";

$subject = "WebSite Feedback";

$message = "

$title

$firstname

$surname

$address

$email

$phone

$foundsiteby

$brochure

$homedemo

$callback

";

$extra = "From: $email";

mail( "me@domain.com", "WebSite Feedback",
$message, "From: $email", "-fuser@me@domain.com" );
header( "Location: [domain.com...] );

?>

thanks again
keen to learn..

dreamcatcher

9:12 am on Mar 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Have you tried it? Should be ok. Just one things, the variables inside of $message have no line breaks or anything, so the $message text might get messy. I would structure it like this:


$message = "Title: " . $title . "\n";
$message .= "First Name: " . $firstname . "\n";
$message .= "Last Name: " . $surname . "\n";
$message .= "First Name: " . $firstname . "\n";
$message .= "Address: " . $address . "\n";
$message .= "E-Mail: " . $email . "\n";
$message .= "Phone: " . $phone . "\n";
$message .= "Site Found By: " . $foundsiteby . "\n";
$message .= "Brochure: " . $brochure . "\n";
$message .= "Home Demo: " . $homedemo . "\n";
$message .= "Call Back: " . $callback . "\n";

The .= is called 'concatenation. It joins all the strings togther. Might look a little better.

Give it a try.

dc

keentolearn

12:28 pm on Mar 21, 2005 (gmt 0)

10+ Year Member



Hi

Many thanks for the help - i will give it a go.

Can you point me to any user friendly tutorials / books that shows using .php in a building blocks kind of way.

thanks again

keen to learn..