...

View Full Version : PLEASE HELP... any ideas :(



lozbenson
11-01-2009, 01:42 PM
This is my email php script below... my problem in when I insert value="name" into the name part of the form...

if a user clicks "send" it recognises the name as "name"...

is there any way of not accepting the name, "name", or the email, "email"?

I hope you understand what i mean... I have attached a link of what I want it looks like... its just the registering of the name and email that doesn't work on my site...


<?php
if(isset($_POST['send'])){
$to = $_REQUEST['sendto'] ; // change all the following to $_POST
$from = $_REQUEST['Email'] ;
$name = $_REQUEST['Name'] ;
$headers = "From: $from";
$subject = "Web Contact Data";

$fields = array();
$fields{"Name"} = "Name";
$fields{"Email"} = "Email";

$body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }

$headers2 = "From: noreply@erbimages.com";
$subject2 = "Thank you for contacting us.";
$autoreply = "Thank you for contacting us. Somebody will get back to you as soon as possible, usually within 48 hours.";
$send=false;
if($name == '') {$error= "You have not entered your name, please try again.";}
else {
if($from == '') {$error= "You have not entered a valid email address, please try again.";}
else {
$send = mail($to, $subject, $body, $headers);
$send2 = mail($from, $subject2, $autoreply, $headers2);
}
if(!isset($error) && !$send)
$error= "We have encountered an error sending your mail, please notify service@erbimages.com"; }
}// end of if(isset($_POST['send']))
?>



<div class="index_register">
<li id="index_register_title">
<b>Register</b>
</li>
<li><div id="section_error_li"><p>
<?php
if(isset($error))
echo '<span id="section_error">'.$error.'</span>';
if(isset($send) && $send== true){
echo 'Thank you, your message has been sent.';
}
if(!isset($_POST['send']) || isset($error))
?>
</div></p></li>
<li>
<form method="post" action="index.php">
<p><select name="sendto"><option value="info@erbimages.com">All News</option> <option value="info@erbimages.com">GN</option> <option value="hire@erbimages.com">GM</option> <option value="rf@erbimages.com">L&B</option> <option value="info@erbimages.com">ERB Images</option></select></p>
<p><font style="padding-right: 2em;">Name:</font><input size="14" maxlength="50" name="Name" value="Name"></p>
<p><font style="padding-right: 2em;">Email:</font><input size="14" maxlength="50" name="Email"></p>
<p id="index_register_send"><input type="submit" name="send" value="Send" id="register_send"></p>
</form>
<?php
?>
</li>

</div>


http://www.stratreal.com

abduraooft
11-01-2009, 01:55 PM
if a user clicks "send" it recognises the name as "name"...

if($name == '' || $name=='name') {$error= "You have not entered your name, please try again.";}
To validate email, you need to use a regexp match. Examples can be obtained from http://www.google.com/search?q=preg_match+validate+email

PS: You may enhance(this is just for helping users) your form by adding some javascript to remove the default values given to input elements. See http://www.codingforums.com/showthread.php?t=131094

lozbenson
11-01-2009, 02:03 PM
THANKS, THATS AWESOME...

How would i incorporate:


function check_email_mx($email2) {
if( (preg_match('/(@.*@)(\.\.)(@\.)(\.@)(^\.)/', $email2))
(preg_match('/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}[0-9]{1,3})(\]?)$/',$email2)) ) {
$host = explode('@', $email2);
if(checkdnsrr($host[1].'.', 'MX') ) return true;
if(checkdnsrr($host[1].'.', 'A') ) return true;
if(checkdnsrr($host[1].'.', 'CNAME') ) return true;
}
return false;
}

into my page?


THE OTHER THING I WOULD LOVE TO ASK AND BE HELPED WITH IS...

is there a way or setting up how the noreply email will look when it is sent... i have tried with this:

$autoreply = "Dear Mr Bohaimid,<br />Thank you for registering with www.erbimages.com.<br />To make sure that you continue to receive our email communications, we suggest that you add info@erbimages.com to your address book or Safe Senders list. In Microsoft Outlook, for example, you can add us to your address book by right clicking our address in the 'From' area above and selecting 'Add to Outlook Contacts' in the list that appears.<br />We look forward to you visiting the site, and can assure you that your privacy will continue to be respected at all times.<br />Yours sincerely,<br />ERB Images";

but this does not work... :(

abduraooft
11-01-2009, 03:08 PM
Try
if(!preg_match("/^[[:alnum:]][a-z0-9_.'+-]*@[a-z0-9-]+(\.[a-z0-9-]{2,})+$/",$from))
$error="You have not entered a valid email address, please try again.";

lozbenson
11-01-2009, 03:58 PM
ARHHH I am not sure I have done it correctly...

It works to an extent but then it comes it with:

You have not entered a valid email address, please try again.Thank you, your message has been sent.

Heres what I have... is that right?


<?php
if(isset($_POST['send'])){
$to = $_REQUEST['sendto'] ; // change all the following to $_POST
$from = $_REQUEST['Email'] ;
$name = $_REQUEST['Name'] ;
$headers = "From: $from";
$subject = "Web Contact Data";

$fields = array();
$fields{"Name"} = "Name";
$fields{"Email"} = "Email";

$body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }

$headers2 = "From: noreply@erbimages.com";
$subject2 = "Thank you for contacting us.";
$autoreply = "Dear Mr Bohaimid,<br />Thank you for registering with www.erbimages.com.<br />To make sure that you continue to receive our email communications, we suggest that you add info@erbimages.com to your address book or Safe Senders list. In Microsoft Outlook, for example, you can add us to your address book by right clicking our address in the 'From' area above and selecting 'Add to Outlook Contacts' in the list that appears.<br />We look forward to you visiting the site, and can assure you that your privacy will continue to be respected at all times.<br />Yours sincerely.";
$send=false;
if($name == '' || $name=='Name') {$error= "You have not entered your name, please try again.";}
else {
if($from == '' || $from=='Email') {$error= "You have not entered a valid email address, please try again.";}
else {
if(!preg_match("/^[[:alnum:]][a-z0-9_.'+-]*@[a-z0-9-]+(\.[a-z0-9-]{2,})+$/",$from)) {$error="You have not entered a valid email address, please try again.";}
$send = mail($to, $subject, $body, $headers);
$send2 = mail($from, $subject2, $autoreply, $headers2);
}
if(!isset($error) && !$send)
$error= "We have encountered an error sending your mail, please notify service@erbimages.com"; }
}// end of if(isset($_POST['send']))
?>

abduraooft
11-01-2009, 04:05 PM
if($from == '' || $from=='Email') {$error= "You have not entered a valid email address, please try again.";}
else {
if(!preg_match("/^[[:alnum:]][a-z0-9_.'+-]*@[a-z0-9-]+(\.[a-z0-9-]{2,})+$/",$from)) {$error="You have not entered a valid email address, please try again.";}
$send = mail($to, $subject, $body, $headers);
$send2 = mail($from, $subject2, $autoreply, $headers2);
} should be like

if(!preg_match("/^[[:alnum:]][a-z0-9_.'+-]*@[a-z0-9-]+(\.[a-z0-9-]{2,})+$/",$from)) $error= "You have not entered a valid email address, please try again.";}
else {
{
$send = mail($to, $subject, $body, $headers);
$send2 = mail($from, $subject2, $autoreply, $headers2);
}
You don't need to check against null in the case of email, as that regexp take cares of all :)

lozbenson
11-01-2009, 05:00 PM
Thanks so much... thats really GREAT...!!!

:thumbsup:

Do you have any ideas regarding the no reply area?

met
11-01-2009, 05:24 PM
you need to set HTML headers to display html in emails

i use




$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Enquiries @ My Site <no-respond@mysite.com>' . "\r\n";

mail($sendto, $subject, $message, $headers); /* change $sendto, $subject, $message accordingly */


will need adapting slightly for your purpose.

lozbenson
11-01-2009, 05:32 PM
SORRY BUT I AM A NOVICE...

what do I remove and where to I put that?

:confused:

met
11-01-2009, 05:38 PM
// snip

$subject2 = "Thank you for contacting us.";
$autoreply = "<html><body><p>Dear Mr Bohaimid,</p><p>Thank you for registering with www.erbimages.com.</p>
<p>To make sure that you continue to receive our email communications, we suggest that you add info@erbimages.com to your address book or Safe Senders list. </p>
<p>In Microsoft Outlook, for example, you can add us to your address book by right clicking our address in the
'From' area above and selecting 'Add to Outlook Contacts' in the list that appears.</p>
<p>We look forward to you visiting the site, and can assure you that your privacy will continue to be respected at all times.</p><p>Yours sincerely.</p></body></html>";

$headers2 = 'MIME-Version: 1.0' . "\r\n";
$headers2 .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers2 .= 'From: noreply@erbimages.com' . "\r\n";

mail($from, $subject2, $autoreply, $headers2);

lozbenson
11-01-2009, 06:48 PM
FANTASTIC...

Is there anyway of making the name... where it now says Mr Bohaimid... to state the name that the person inserts?

Also how to put a link in the autoreply??

Thanks for all your help!!!

:thumbsup::thumbsup::thumbsup::thumbsup:

met
11-01-2009, 09:44 PM
// snip

$subject2 = "Thank you for contacting us.";
$autoreply = "<html><body><p>Dear " . $name . ",</p><p>Thank you for registering with <a href='http://www.erbimages.com'>ERB Images</a>.</p>
<p>To make sure that you continue to receive our email communications, we suggest that you add <a href='mailto:info@erbimages.com'>info@erbimages.com</a> to your address book or Safe Senders list. </p>
<p>In Microsoft Outlook, for example, you can add us to your address book by right clicking our address in the
'From' area above and selecting 'Add to Outlook Contacts' in the list that appears.</p>
<p>We look forward to you visiting the site, and can assure you that your privacy will continue to be respected at all times.</p><p>Yours sincerely.</p></body></html>";

$headers2 = 'MIME-Version: 1.0' . "\r\n";
$headers2 .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers2 .= 'From: noreply@erbimages.com' . "\r\n";

mail($from, $subject2, $autoreply, $headers2);


but if you have to ask that then you should probably look in to basic html...
$autoreply is just a variable containing a string of text, which happens to be HTML. modify the HTML as required to change the appearance of the email when it is received by the user.

lozbenson
11-03-2009, 04:19 PM
Gotcha, thanks alot once again...

I have been learning HTML and am now trying to get to grips with this kind of thing...

I have been playing around for a while now on this and I wondered if there was a way, that when an error occurs it doesn't delete what they have inserted into the fields???

:confused:

Do you know of any codes???

:thumbsup: Thanks once again for before!!!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum