/    Sign up×
Community /Pin to ProfileBookmark

Mail Forms Functions

good day,

i have this code in my site and it works perfectly fine. but the problem is, it doesnt check whether the email of the sender is correct. it sends the mail even if the email address of the sender is not in a valid format. it also redirect me to my thanks page. can anyone share his/her knowledge about PHP mail() function. can anyone make the code im using as perfectly as it could. pleasee… helps are much appreciated.

[CODE]<?php
$name=$_POST[‘name’];
$email=$_POST[’email’];
$subject1=$_POST[‘subject’];
$message=$_POST[‘message’];
$ip=$_SERVER[“REMOTE_ADDR”];
$host = gethostbyaddr($_SERVER[‘REMOTE_ADDR’]);
$host = $ip.”.”.$host;
$mon=date(m);
$day=date(j);
$year=date(y);
$hour=date(g);
$min=date(i);
$sec=date(s);
$hour=$hour-2;
if($hour<=0) { $hour+=12; }
$ts = “$hour:$min:$sec on $mon/$day/$year”;
$subject=”[My Subject]:”.” $subject1″;
$body=”
Message from: $name
Subject: $subject1
E-mail: $email
Message: $message

Host: $host
Time: $ts”;

if (mail(’[email protected]’, $subject, $body,”From: {$name} <{$email}>”)):
header(“location:/thanks.html”);
else:
header(“location:/mailerror.html”);
endif;
?>[/CODE]

and also where do i gonna insert the CC and BCC in this code?
can PHP mail() function can hold more than 1 email at the TO? not in CC and BCC

to post a comment
PHP

8 Comments(s)

Copy linkTweet thisAlerts:
@gameguy43May 10.2005 — doesn't exactly answer your question but this:
[code=php]
$mon=date(m);
$day=date(j);
$year=date(y);
$hour=date(g);
$min=date(i);
$sec=date(s);
$hour=$hour-2;
if($hour<=0) { $hour+=12; }
$ts = "$hour:$min:$sec on $mon/$day/$year";
[/code]

can be simplified to
[code=php]
$ts = date(g:i:s on m/j/y);
[/code]

the forum filtered it out, but u need a "" before the o and n

not sure why you wanted to mess with the hour, it should be right.
Copy linkTweet thisAlerts:
@ne3ro0authorMay 11.2005 — OK!! thanks for that tip..

please.. help with my problem.. can PHP mail() function handle more than one [B]TO's[/B], not in [B]CC[/B] and [B]BCC[/B]
Copy linkTweet thisAlerts:
@LiLcRaZyFuZzYMay 11.2005 — yes you can have many "to's"

[code=php]
/* recipients */
$to = "[email protected]" . ", " ; // note the comma
$to .= "[email protected]";
[/code]


for "cc's" and "bcc's" you have to add additional headers, be sure to check what the manual says about the [URL=http://www.php.net/manual/en/function.mail.php]mail() function[/URL] . they also have some useful examples.
Copy linkTweet thisAlerts:
@BeachSideMay 11.2005 — This...
[code=php]
if (mail('[email protected]', $subject, $body,"From: {$name} <{$email}>")):
header("location:/thanks.html");
else:
header("location:/mailerror.html");
[/code]

Will always return true so it will always send it.


You need something like
[code=php]
if($email == "[email protected]") {
send your email
} else {
give them an error
}
[/code]


Hope that helps

::Edit::

Oh and you are asking the impossible of the mail() function if you want it to validate an email address. You would do better using a regular expression to check that
Copy linkTweet thisAlerts:
@bokehMay 11.2005 — [code=php]
<?php
//If you have lots of addresses to send to
//you could put them all in an array and then
//loop through each one individually

$to = array();

$to[] = '[email protected]';
$to[] = '[email protected]';
$to[] = '[email protected]';
$to[] = '[email protected]';
$to[] = '[email protected]';

foreach($to as $email){
mail($email, 'subject', 'message');
}
?>
[/code]
Copy linkTweet thisAlerts:
@ne3ro0authorMay 13.2005 — Thanks for all the help about the TO's...

about the email validation.. can anyone show me example on how to validate the email of the sender?
Copy linkTweet thisAlerts:
@bokehMay 13.2005 — Thanks for all the help about the TO's...

about the email validation.. can anyone show me example on how to validate the email of the sender?[/QUOTE]

[URL=http://www.webdeveloper.com/forum/showthread.php?t=65057&highlight=validate]Read my third post in this thread.[/URL]
×

Success!

Help @ne3ro0 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...