Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Mail

MULTIPLE PAGE contact form - email problem

the mail() function

Moderators: macek, egami, gesf

MULTIPLE PAGE contact form - email problem

Postby perihan » Sat Sep 18, 2010 3:59 am

Hi everyone,

Im working on a multiple page form. I made a simple form, to test. When i compile all fields, and send, i get the message "not send, email not valid."

The code works fine with just one page, it starts to give be a problem with more.

I use to contact pages and 1 send. The entension is that the first send sends it to de second, and the second to the send.

My codes:

contact1.php

<form method="post" action="contact2.php">
Name:<br /><input name="name" type="text" size="30" maxlength="40" /><br /><br />
Email:<br /><input name="email" type="text" size="30" maxlength="40" /><br /><br />

<input type="reset" value="Reset" />&nbsp; <a href="contact2.php">next</a>
</form>

--------------------------contact2.php--------------------------

<form method="post" action="send1.php">
<input type="hidden" name="name" value="<?php echo $_POST['name']; ?>" />
<input type="hidden" name="email" value="<?php echo $_POST['email']; ?>" />

Name:<br /><input name="name2" type="text" size="30" maxlength="40" /><br /><br />
Subject:<br /><input name="subject2" type="text" size="30" maxlength="40" /><br /><br />

<input type="reset" value="Reset" />&nbsp; <input type="submit" value="Send" />
</form>

------------------------send1.php--------------------------------

<?php
$receiverMail = "myemail";

$name = ltrim(rtrim(strip_tags(stripslashes($_POST['name']))));
$email = ltrim(rtrim(strip_tags(stripslashes($_POST['email']))));

$name2 = ltrim(rtrim(strip_tags(stripslashes($_POST['name2']))));
$subject2 = ltrim(rtrim(strip_tags(stripslashes($_POST['subject2']))));

$ip = getenv("REMOTE_ADDR");
$msgformat = "From: $name ($ip)\nEmail: $email\n\n$msg";

// VALIDATION

\
$email = htmlentities($_POST['email'],ENT_QUOTES);
$email_check = preg_match("/^[a-z0-9_\.-]+@([a-z0-9]+([\-]+[a-z0-9]+)*\.)+[a-z]{2,7}$/i", $email);

if($email_check != 1){
echo'Email not valid';
}else{
echo'Thanks';
}

?>

----------------------------

Somebody can help me out here? Please explane it to me at noob level! THANKS!!
perihan
New php-forum User
New php-forum User
 
Posts: 4
Joined: Sat Sep 18, 2010 3:46 am

Re: MULTIPLE PAGE contact form - email problem

Postby macek » Sun Sep 19, 2010 12:23 am

You don't submit FORM on the first page!

Code: Select all
<form method="post" action="contact2.php">
Name:<br /><input name="name" type="text" size="30" maxlength="40" /><br /><br />
Email:<br /><input name="email" type="text" size="30" maxlength="40" /><br /><br />

<input type="reset" value="Reset" />&nbsp; [color=#BF0000]<a href="contact2.php">next</a>[/color]
</form>


Code: Select all
<form method="post" action="contact2.php">
Name:<br /><input name="name" type="text" size="30" maxlength="40" /><br /><br />
Email:<br /><input name="email" type="text" size="30" maxlength="40" /><br /><br />

<input type="reset" value="Reset" />&nbsp; [color=#004000][b]<input type="submit" value="Next" />[/b][/color]
</form>


And I suggest to save variables from the first page to SESSION instead of include it to HIDDEN input - skilled users can change HIDDEN INPUTs :D
User avatar
macek
php-forum Active User
php-forum Active User
 
Posts: 277
Joined: Wed Aug 25, 2010 10:42 am

Re: MULTIPLE PAGE contact form - email problem

Postby perihan » Mon Sep 20, 2010 3:20 am

Thanks for your help! Now it tell's me "Thanks", like it has been send. Though I still don't receive anything. Strange is it, what else could be the problem...?

Thanks for helping me out, I really would like to understand this a stuff.......
perihan
New php-forum User
New php-forum User
 
Posts: 4
Joined: Sat Sep 18, 2010 3:46 am

Re: MULTIPLE PAGE contact form - email problem

Postby macek » Mon Sep 20, 2010 7:32 am

Where did U call some function to send email??

http://php.net/manual/en/function.mail.php
User avatar
macek
php-forum Active User
php-forum Active User
 
Posts: 277
Joined: Wed Aug 25, 2010 10:42 am

Re: MULTIPLE PAGE contact form - email problem

Postby perihan » Mon Sep 20, 2010 7:59 am

In the first part of send1.php (check my first message)

<?php
$receiverMail = "myemail";

Should do it, right..? Thanks!
perihan
New php-forum User
New php-forum User
 
Posts: 4
Joined: Sat Sep 18, 2010 3:46 am

Re: MULTIPLE PAGE contact form - email problem

Postby macek » Mon Sep 20, 2010 8:09 am

But you must call function to send mail! How PHP can know that you want to send email without tell it to PHP? AI? :D

Code: Select all
$message = "Line 1\nLine 2\nLine 3";

mail('info@example.com', 'My Subject', $message);
User avatar
macek
php-forum Active User
php-forum Active User
 
Posts: 277
Joined: Wed Aug 25, 2010 10:42 am

Re: MULTIPLE PAGE contact form - email problem

Postby perihan » Tue Sep 21, 2010 6:57 am

Macek, thank you so much for helping me! Im so sorry for my PHP ignorance, I have a long way to go!

I do receive a mail now! Just out of my 4 fields (name,email,name2,subject2) i miss one, subject2! And the email adres it comes from is of my database.... (don't know if this can cause problems..?)

The code seems allright to me, do you see an error? The mistake is in one of these lines right?

------------------------------------------

<?php
$receiverMail = "myemail@world.com";

$name = ltrim(rtrim(strip_tags(stripslashes($_POST['name']))));
$email = ltrim(rtrim(strip_tags(stripslashes($_POST['email']))));
$name2 = ltrim(rtrim(strip_tags(stripslashes($_POST['name2']))));
$subject2 = ltrim(rtrim(strip_tags(stripslashes($_POST['subject2']))));

$ip = getenv("REMOTE_ADDR");
$msgformat = "From: $name ($ip)\nEmail: $email\n\n$subject2";

// VALIDATION

\
$email = htmlentities($_POST['email'],ENT_QUOTES);
$email_check = preg_match("/^[a-z0-9_\.-]+@([a-z0-9]+([\-]+[a-z0-9]+)*\.)+[a-z]{2,7}$/i", $email);

if($email_check != 1){
echo'Email not valid';
}else{
mail('myemail@world.com', $name, $email, $name2, $subject2);
echo'Thanks';
}

?>


---------------------------------------------------------

I would we really happy to solve this problem! Can you please help me out a little bit more, I really appreciate it!

Buy the way, do you know how I can send an mail also to the person who compiled the form...? Thank you for your help!
perihan
New php-forum User
New php-forum User
 
Posts: 4
Joined: Sat Sep 18, 2010 3:46 am

Re: MULTIPLE PAGE contact form - email problem

Postby macek » Sun Sep 26, 2010 4:33 am

Code: Select all

mail($_POST['email'], ,.... );

User avatar
macek
php-forum Active User
php-forum Active User
 
Posts: 277
Joined: Wed Aug 25, 2010 10:42 am

Re: MULTIPLE PAGE contact form - email problem

Postby TheAzyrus » Wed Dec 11, 2013 10:09 pm

Hey perihan, I've written a tutorial on this exact thing check it out http://www.azyrus.com/tutorials/multiple-page-form/.
TheAzyrus
New php-forum User
New php-forum User
 
Posts: 1
Joined: Wed Dec 11, 2013 10:06 pm


Return to PHP coding => Mail

Who is online

Users browsing this forum: Google [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.