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

email validation and send email

the mail() function

Moderators: macek, egami, gesf

email validation and send email

Postby ny1234 » Tue Jan 17, 2012 9:01 am

Hi,

I am trying to validate email then send the email if correct email. Below code is not working for me.

any help?

Thanks.


<?php
$errors = '';
$myemail = 'saf23@hotmail.com';
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['message']))
{
$errors .= "\n Error: all fields are required";
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$message = $_POST['message'];
if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",
$email_address))
{
$errors .= "\n Error: Invalid email address";
}
Else
mail("saf23@hotmail.com", "$subject", $message, "From:" . $email);
echo "Thank you for using our mail form";

?>


--i entered invalid email address but it cant verify that it is invalid. i was expecting error message. if valid email, then just send the email.

Thanks.
ny1234
New php-forum User
New php-forum User
 
Posts: 5
Joined: Tue Nov 08, 2011 12:59 pm

Re: email validation and send email

Postby TheProdigyGuy » Tue Jan 17, 2012 2:47 pm

Hello ny1234,
Just replace that
Code: Select all
preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",
$email_address))

With:
Code: Select all
if(!filter_var($email_address,FILTER_VALIDATE_EMAIL));

and it should work as expected.
TheProdigyGuy
New php-forum User
New php-forum User
 
Posts: 215
Joined: Wed Dec 07, 2011 5:25 pm

Re: email validation and send email

Postby ny1234 » Wed Jan 18, 2012 9:43 am

Sorry. it didnt work.

Thanks.
ny1234
New php-forum User
New php-forum User
 
Posts: 5
Joined: Tue Nov 08, 2011 12:59 pm

Re: email validation and send email

Postby TheProdigyGuy » Wed Jan 18, 2012 11:44 am

ny1234,Dear you need understand that you have to create Simple HTML FORM firstly and then pass all your $_POST['message'] etc. to that PHP script.
Ofcourse it will not work for you without HTML Form.
TheProdigyGuy
New php-forum User
New php-forum User
 
Posts: 215
Joined: Wed Dec 07, 2011 5:25 pm

If silence is still

Postby rfg1rfwcdh » Wed Jan 25, 2012 6:18 pm

I have been out of place in the world catch of heaven ,louboutin



let me stop in between dreams and reality

sink



it is

hustle and bustle of a dream Love in

I suspended in the earth 's surface

can not break free



gods ah if you flying in this land

please let me fly away let me

If silence is still

Please bring to my soul

look like another world of contemporary prose books

相关的主题文章:


http://www.shell.linux.se/hanski/forums/viewtopic.php?t=435335

http://www.udp.org.tw/moderated/index.php?topic=166721.msg194398#msg194398


Tom Cruise' vehicle "Mission Impossible: Ghost Protocol" was edged to third place, garnering 11.5 million dollars in ticket stubs, which registered a 42 percent drop from last week. It is on track for a total of 186.7 million dollars for five weeks in exhibition.
rfg1rfwcdh
New php-forum User
New php-forum User
 
Posts: 1
Joined: Wed Jan 11, 2012 7:23 pm


Return to PHP coding => Mail

Who is online

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

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