Jump to content

pauldreed

Members
  • Posts

    13
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

pauldreed's Achievements

Member

Member (2/5)

0

Reputation

  1. haaglin Thanks, that works great, are you aware of any other formatting options that I could use?
  2. I have a php contact page form which sends enquiries to my email account and also a confirmation email to the sender, telling them that I will respond in due course. This works great, but how can I introduce a line break/new paragraph into the automated email, so the email looks formatted and not just a long string of words?? [code]# send confirmation email if($sendnotification == true) { $notification_message = "Thank you for contacting $websitetitle, $sender_name. We have received your email and will be in touch shortly"; $notification_subject = "Thanks for your message to $websitetitle."; mail($sender_email, $notification_subject, $notification_message, "From: $recipient");             header('Location: http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?success');         }[/code]
  3. Alpine Your code works, but I am still not sure what you have added/changed and why, I'll get my glasses and have another look! But thanks again, youve been a great help. Heyray Sorry your'e amendment errors EDIT>> Found the missing bracket at the end!  but how did you find it? Did you work through the code line by line, or somehow find the error by using an application?
  4. Thanks Alpine for your patience, but I'm afraid that doesnt work either. I have included a slightly bigger chunk of code below, from the start up to the next section - function error() which may may make it clearer. [code]<?php # fill this in with the address to which the email will be sent $recipient = 'paul@gmail.com'; # Send notification to sender (use false if not required) $sendnotification = true; # Your web site title (John Doe's Site) $websitetitle = 'mysite'; session_start(); define('CAPTCHA_PATH', $_SERVER['DOCUMENT_ROOT'].'/captcha/'); if(isset($_GET['i'])) {     captcha_image(); } elseif(isset($_POST['submit'])) { if(!($error = error())) { $sender_name = ucwords($_POST['name']); $sender_email = $_POST['email']; $headers = "From: $sender_name <$sender_email>\r\n"; $headers .= "Reply-To: $sender_name <$sender_email>\r\n"; $headers .= "Return-Path: $sender_name <$sender_email>\r\n"; $subject = 'Webform enquiry from '.$_POST['name'].' via '.$_SERVER['HTTP_HOST']; $message = "Sender: $sender_name \r\n\r\n". "Email: $sender_email \r\n\r\n". "Telephone: {$_POST['tel']} \r\n\r\n". "Prefered Contact time: {$_POST['time']} \r\n\r\n". "Message: {$_POST['comments']} \r\n\r\n". $users_ip = 'IP Address of sender: '.$_SERVER['REMOTE_ADDR']; if(mail($recipient, $subject, $message, $headers)) # send confirmation email if($sendnotification == true) { $notification_message = "Thank you for contacting $websitetitle, $sender_name. We have received your email and will be in touch shortly"; $notification_subject = "Thanks for your message to $websitetitle."; mail($sender_email, $notification_subject, $notification_message, "From: $recipient");         {             header('Location: http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?success');         }         else         {             header('Location: http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?failure');         }     } } [/code] Now if I comment out this section; [code]<?php # send confirmation email #if($sendnotification == true) { #$notification_message = "Thank you for contacting $websitetitle, $sender_name. We have received your email and will be in touch shortly"; #$notification_subject = "Thanks for your message to $websitetitle."; #mail($sender_email, $notification_subject, $notification_message, "From: $recipient");     #}[/code] the form is error free.
  5. I have a 'contact me' page with a form for visitors to enter details. The underlying code works great (thanks to earlier help in this forum), but to improve it, I want to add a new bit of code to email a confirmation email back to the visitor as well. I have attached a chunk of code below, but when I add the code between the 'send confirmation email' comments, the form errors. Can anyone see what the problem is please. I am very new to php and finding it difficult to remedy errors. I have defined $sendnotification and $websitetitle earlier in the code. [code]if(!($error = error())) { $sender_name = ucwords($_POST['name']); $sender_email = $_POST['email']; $headers = "From: $sender_name <$sender_email>\r\n"; $headers .= "Reply-To: $sender_name <$sender_email>\r\n"; $headers .= "Return-Path: $sender_name <$sender_email>\r\n"; $subject = 'Webform enquiry from '.$_POST['name'].' via '.$_SERVER['HTTP_HOST']; $message = "Sender: $sender_name \r\n\r\n". "Email: $sender_email \r\n\r\n". "Telephone: {$_POST['tel']} \r\n\r\n". "Prefered Contact time: {$_POST['time']} \r\n\r\n". "Message: {$_POST['comments']} \r\n\r\n". $users_ip = 'IP Address of sender: '.$_SERVER['REMOTE_ADDR']; if(mail($recipient, $subject, $message, $headers)) # send confirmation email if($sendnotification == true) { $notification_message = "Thank you for contacting $websitetitle, $sender_name. We have received your email and will be in touch shortly"; $notification_subject = "Thanks for your message to $websitetitle."; mail($sender_email, $notification_subject, $notification_message, "From: $recipient"); } # end of confirmation email code[/code]
  6. Alpine, thanks I used your code and I now get the email exactly as I want it! To take the code one stage further, to also send a confirmation email to the person submitting the form, I have added on the code below, but there is some error which prevents the page from displaying in the browser. I have set the variables $sendnotification and $websitetitle earlier in the code, and if I remove everything between the 'send confirmation email' comments, I go back to a working page. Is there something stupid creating an error with my addition? [code]if(!($error = error())) { $sender_name = ucwords($_POST['name']); $sender_email = $_POST['email']; $headers = "From: $sender_name <$sender_email>\r\n"; $headers .= "Reply-To: $sender_name <$sender_email>\r\n"; $headers .= "Return-Path: $sender_name <$sender_email>\r\n"; $subject = 'Webform enquiry from '.$_POST['name'].' via '.$_SERVER['HTTP_HOST']; $message = "Sender: $sender_name \r\n\r\n". "Email: $sender_email \r\n\r\n". "Telephone: {$_POST['tel']} \r\n\r\n". "Prefered Contact time: {$_POST['time']} \r\n\r\n". "Message: {$_POST['comments']} \r\n\r\n". $users_ip = 'IP Address of sender: '.$_SERVER['REMOTE_ADDR']; if(mail($recipient, $subject, $message, $headers)) # send confirmation email if($sendnotification == true) { $notification_message = "Thank you for contacting $websitetitle, $sender_name. We have received your email and will be in touch shortly"; $notification_subject = "Thanks for your message to $websitetitle."; mail($sender_email, $notification_subject, $notification_message, "From: $recipient"); } # end of confirmation email code [/code]
  7. I have a contact form on my website which sends the contacts details to my email. However, when the email arrives it indicates that it has been sent from my server, whereas I want it to show that it has been sent from the email address entered on the form. Example; I get  email which includes the sender address as serverone.jabweb.co.uk, but the email of the person submiting the form is jan@google.com. If I then try to reply to the message, it would be sent to serverone.jabweb.co.uk instead of jan@google.com. As being new to php, what do I need to alter to change this. I have attached part of the code below. <?php # fill this in with the address to which the email will be sent $recipient = 'robbie@tiscali.co.uk'; session_start(); define('CAPTCHA_PATH', $_SERVER['DOCUMENT_ROOT'].'/captcha/'); if(isset($_GET['i'])) {     captcha_image(); } elseif(isset($_POST['submit'])) {     if(!($error = error()))     {         $subject = 'Mail from '.$_SERVER['HTTP_HOST'].' webform';         $message = "Sender: ".ucwords($_POST['name'])." \r\n\r\n".         "Email: {$_POST['email']} \r\n\r\n".     "Happy: {$_POST['happy']} \r\n\r\n".         "Message: {$_POST['comments']} \r\n\r\n". $users_ip = 'IP Address of sender: '.$_SERVER['REMOTE_ADDR'];                             if(@mail($recipient, $subject, $message))         {             header('Location: http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?success');         }         else         {             header('Location: http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?failure');         }     } } function error() {     if(empty($_POST['name']))     {         return 'ERROR: The name field is empty.';     }     if(preg_match('/[^a-zA-Z ]/', $_POST['name']))     {         return 'ERROR: The name field contains invalid characters.';     }     if(empty($_POST['email']))     {         return 'ERROR: The email field is empty.';     }     if(!eregi('^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,6})$', $_POST['email']))     {         return 'ERROR: The email field contains invalid syntax.';     }     if(empty($_POST['comments']))     {         return 'ERROR: The comments field is empty.';     }     if(!captcha_validate())     {         return 'ERROR: Incorrect security code entered.';     }     return false; The rest of the code goes onto the Captcha code.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.