oavs Posted August 25, 2010 Share Posted August 25, 2010 Hi I really would appreciate if some phpfreak can help me with this please :'(. I need to my contact page send emails so that when recipient receives it, it comes with the correct domain (same as the web address) it is coming from rather than the server name. At the moment they are coming as abcd20@elessar.nocdirect.com and would like them come as abcd20@myowndomain.com (lets say my password for that email is 'zzzaaa' and the domain was myowndomain.com ) Here is my email contact php script which works fine and hopefully would not have to change too much. My Contact form is posting to 'send.php' . On top of my contacts page there is a js script for 'jquery.js' and some jQuery stuff for validation.. Have seen many scripts but could not adapt to my existing send.php script. Can you please help? ------ Content of 'send.php' ----------------------------------- <?php if(!$_POST) exit; $email = $_POST['email']; //$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS'; if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){ $error.="Invalid email address entered"; $errors=1; } if($errors==1) echo $error; else{ $values = array ('name','email','phone','message'); $required = array('name','email','phone','message'); $your_email = "abcd20@myowndomain.com"; $email_subject = "New Message: ".$_POST['subject']; $email_content = "New message:\n"; foreach($values as $key => $value){ if(in_array($value,$required)){ if ($key != 'subject' && $key != 'company') { if( empty($_POST[$value]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; } } $email_content .= $value.': '.$_POST[$value]."\n"; } } if(@mail($your_email,$email_subject,$email_content)) { echo 'Message sent!'; } else { echo 'ERROR!'; } } ?> -------------------------------------------------------------------------------- Quote Link to comment https://forums.phpfreaks.com/topic/211686-help-with-sending-mail-from-php-using-smtp-authentication/ Share on other sites More sharing options...
dolrichfortich Posted August 25, 2010 Share Posted August 25, 2010 Add additional parameter on the mail function to specify the email sender. Something like this. <?php $to = 'nobody@example.com'; $subject = 'the subject'; $message = 'hello'; $headers = 'From: webmaster@example.com' . "\r\n" . 'Reply-To: webmaster@example.com'; mail($to, $subject, $message, $headers); ?> Quote Link to comment https://forums.phpfreaks.com/topic/211686-help-with-sending-mail-from-php-using-smtp-authentication/#findComment-1103526 Share on other sites More sharing options...
oavs Posted August 25, 2010 Author Share Posted August 25, 2010 can you show me where and how exactly please. This is my problem I have no idea how and where it supposed to go. Thanks for your kind reply. Quote Link to comment https://forums.phpfreaks.com/topic/211686-help-with-sending-mail-from-php-using-smtp-authentication/#findComment-1103717 Share on other sites More sharing options...
dolrichfortich Posted August 27, 2010 Share Posted August 27, 2010 Okay, try this one. Let me know if it works for you. <?php if(!$_POST) exit; $email = $_POST['email']; //$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS'; if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )) { $error.="Invalid email address entered"; $errors=1; } if($errors==1) echo $error; else { $values = array ('name','email','phone','message'); $required = array('name','email','phone','message'); $from_email = 'abcd20@myowndomain.com'; $your_email = "abcd20@myowndomain.com"; $email_subject = "New Message: ".$_POST['subject']; $headers = "From: {$from_email}\r\nReply-To: {$from_email}"; $email_content = "New message:\n"; foreach($values as $key => $value) { if(in_array($value,$required)) { if ($key != 'subject' && $key != 'company') { if( empty($_POST[$value]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; } } $email_content .= $value.': '.$_POST[$value]."\n"; } } if(@mail($your_email,$email_subject,$email_content, $headers)) { echo 'Message sent!'; } else { echo 'ERROR!'; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/211686-help-with-sending-mail-from-php-using-smtp-authentication/#findComment-1104248 Share on other sites More sharing options...
MadTechie Posted August 27, 2010 Share Posted August 27, 2010 As far as i am aware, mail doesn't support SMTP Authentication, your better off going with PEAR Mail package or a fsocket system like phpMailer Of course you can just change your reply address, but that will only send from a non-authenticated account Quote Link to comment https://forums.phpfreaks.com/topic/211686-help-with-sending-mail-from-php-using-smtp-authentication/#findComment-1104250 Share on other sites More sharing options...
oavs Posted August 27, 2010 Author Share Posted August 27, 2010 Hey dolrichfortich! Are some genius or something? because it has worked and you must be! and until now no one has come of with such a simple solution to my problem. Many many thanks mate :-) First go and it worked. ..I am happy :-) Quote Link to comment https://forums.phpfreaks.com/topic/211686-help-with-sending-mail-from-php-using-smtp-authentication/#findComment-1104262 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.