Cybermax Posted October 23, 2013 Share Posted October 23, 2013 I'm busy building an online html form that posts to a *.php file (Below). Were do I add in a line of code that sends the subscribe a copy of the completed form. On another note, the form successfully post when completed, but the client informed us that we hasn't received a copy - is there anything I'm missing? <?php if(isset($_POST['email'])) { $email_to = "EmailTo"; $email_subject = "Online Booking Form"; function died($error) { // your error code can go here echo "We are very sorry, but there were error(s) found with the form you submitted. "; echo "These errors appear below.<br /><br />"; echo $error."<br /><br />"; echo "Please go back and fix these errors.<br /><br />"; die(); } // validation expected data exists if(!isset($_POST['first_name']) || !isset($_POST['last_name']) || !isset($_POST['company_name']) || !isset($_POST['email']) || !isset($_POST['booking_date']) || !isset($_POST['session_times']) || !isset($_POST['number_players']) || !isset($_POST['confirmation_code'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $first_name = $_POST['first_name']; // required $last_name = $_POST['last_name']; // required $company_name = $_POST['company_name']; // not required $email_from = $_POST['email']; // required $booking_date = $_POST['booking_date']; // required $session_times = $_POST['session_times']; // required $number_players = $_POST['number_players']; // required $confirmation_code = $_POST['confirmation_code']; // required $error_message = ""; $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; if(!preg_match($email_exp,$email_from)) { $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "Online Booking Results.\r\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "First Name: ".clean_string($first_name)."\r\n"; $email_message .= "Last Name: ".clean_string($last_name)."\r\n"; $email_message .= "Your Company: ".clean_string($company_name)."\r\n"; $email_message .= "Email Address: ".clean_string($email_from)."\r\n"; $email_message .= "Booking Date: ".clean_string($booking_date)."\r\n"; $email_message .= "Session Times: ".clean_string($session_times)."\r\n"; $email_message .= "Number of Players: ".clean_string($number_players)."\r\n"; $email_message .= "Confirmation Code: ".clean_string($confirmation_code)."\r\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(). "\r\n" . "MIME-Version: 1.0\r\n" . "Content-Type: text/html; charset=utf-8\r\n" . "Content-Transfer-Encoding: 8bit\r\n\r\n"; ini_set("SMTP","IPADDRESS"); ini_set("smtp_port", "25"); ini_set("sendmail_from", "SendFrom"); ini_set('auth_username','Username'); ini_set('auth_password','Password'); @mail($email_from, $email_subject, $email_message, $headers); @mail($email_to, $email_subject, $email_message, $headers); header('Location: URL'); ?> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/283215-html-online-form-post-to-php/ Share on other sites More sharing options...
BrodaNoel Posted October 23, 2013 Share Posted October 23, 2013 (edited) First, do that: Replace @mail($email_from, $email_subject, $email_message, $headers); @mail($email_to, $email_subject, $email_message, $headers); for this: $result1 = mail($email_from, $email_subject, $email_message, $headers); $result2 = mail($email_to, $email_subject, $email_message, $headers); var_dump($result1); var_dump($result2); If both are true, that is OK. Else, we have a problem to send the e-mail. If both are true, try send a e-mail to your email account. If you recive the e-mail, may be your client have recive the e-mail in SPAM folder. If you dont recive the e-mail, sooo... we can have 246524652465 possible erros. But, first, test all that. Edited October 23, 2013 by BrodaNoel Quote Link to comment https://forums.phpfreaks.com/topic/283215-html-online-form-post-to-php/#findComment-1455124 Share on other sites More sharing options...
Cybermax Posted October 24, 2013 Author Share Posted October 24, 2013 Thank for the feedback. I made the changes and the following error is thrown; Warning: mail() [function.mail]: Failed to connect to mailserver at "IPAddress" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\Inetpub\vhosts\domain\httpdocs\FormMailAuth.php on line 78SMTP Settings Verified and TestedWarning: mail() [function.mail]: Failed to connect to mailserver at "IPAddress" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\Inetpub\vhosts\domain\httpdocs\FormMailAuth.php on line 79SMTP Socket Verified and Tested bool(false) bool(false)Warning: Cannot modify header information - headers already sent by (output started at C:\Inetpub\vhosts\domain\httpdocs\FormMailAuth.php:78) in C:\Inetpub\vhosts\domain\httpdocs\FormMailAuth.php on line 82 Kindly advise, thanks Quote Link to comment https://forums.phpfreaks.com/topic/283215-html-online-form-post-to-php/#findComment-1455177 Share on other sites More sharing options...
BrodaNoel Posted October 28, 2013 Share Posted October 28, 2013 Ohhh... I understand... You must change this data for the correct data: ini_set("SMTP","IPADDRESS"); ini_set("smtp_port", "25"); ini_set("sendmail_from", "SendFrom"); ini_set('auth_username','Username'); ini_set('auth_password','Password'); You have all this information of your SMTP server? You have a SMTP server? (your server should be enable this) Quote Link to comment https://forums.phpfreaks.com/topic/283215-html-online-form-post-to-php/#findComment-1455855 Share on other sites More sharing options...
Ch0cu3r Posted October 28, 2013 Share Posted October 28, 2013 The builtin php mail() function does not support smtp authentication. If your smpt server requires authentication for sending emails then use PHPMailer Quote Link to comment https://forums.phpfreaks.com/topic/283215-html-online-form-post-to-php/#findComment-1455873 Share on other sites More sharing options...
Cybermax Posted October 28, 2013 Author Share Posted October 28, 2013 (edited) I added those values in to protect my clients server. When running the online form the below error is encountered mail() [function.mail]: SMTP server response: 503 This mail server requires authentication when attempting to send to a non-local e-mail address. Please check your mail client settings or contact your administrator to verify that the domain or address is defined for this server. inChanges made to the *.php $result1 = mail($email_from, $email_subject, $email_message, $headers); $result2 = mail($email_to, $email_subject, $email_message, $headers); var_dump($result1); var_dump($result2); Edited October 28, 2013 by Cybermax Quote Link to comment https://forums.phpfreaks.com/topic/283215-html-online-form-post-to-php/#findComment-1455882 Share on other sites More sharing options...
Ch0cu3r Posted October 28, 2013 Share Posted October 28, 2013 In order for the email to be sent the smtp server requires authentication. In other words before you can send the email, the smtp sever requires a username/password that is authorised to send the email. The standard mail() does not have this capability. There is no PHP setting for this either. You will need to use the PHPMailer script I linked to. Look at the example code for sending an email using authentication here http://phpmailer.worxware.com/index.php?pg=examplebsmtp Quote Link to comment https://forums.phpfreaks.com/topic/283215-html-online-form-post-to-php/#findComment-1455885 Share on other sites More sharing options...
BrodaNoel Posted October 28, 2013 Share Posted October 28, 2013 Wait wait wait... This: ini_set("SMTP","IPADDRESS"); ini_set("smtp_port", "25"); ini_set("sendmail_from", "SendFrom"); ini_set('auth_username','Username'); ini_set('auth_password','Password'); That isn't work... why that is not used by "mail()" function. Try using this library: "PHPMailer". Search about that in Google. This library use STMP server to sends emails and in a file configuration you can push the data to access at SMTP server. I think that all the information is here: https://github.com/PHPMailer/PHPMailer But, if not, search about this library in Google. Is a single file, is very easy to use. Quote Link to comment https://forums.phpfreaks.com/topic/283215-html-online-form-post-to-php/#findComment-1455924 Share on other sites More sharing options...
BrodaNoel Posted October 28, 2013 Share Posted October 28, 2013 Here you can see an example (in Spanish, but, only look at the code): http://www.elserver.com/ayuda/como-envio-correos-con-php-por-smtp-phpmailer/ Saludos! Quote Link to comment https://forums.phpfreaks.com/topic/283215-html-online-form-post-to-php/#findComment-1455925 Share on other sites More sharing options...
Ch0cu3r Posted October 28, 2013 Share Posted October 28, 2013 @BrodaNoel is my posts not in english? I have linked to phpmailer twice Quote Link to comment https://forums.phpfreaks.com/topic/283215-html-online-form-post-to-php/#findComment-1455947 Share on other sites More sharing options...
BrodaNoel Posted October 29, 2013 Share Posted October 29, 2013 I'm sorry Ch0cu3r. Read my sign... "Sorry for my english"... My english is soo bad. I had not read your answer. Sorry. Quote Link to comment https://forums.phpfreaks.com/topic/283215-html-online-form-post-to-php/#findComment-1456012 Share on other sites More sharing options...
Cybermax Posted November 4, 2013 Author Share Posted November 4, 2013 Thanks for all the assistance guys. Got a couple of more questions regarding the script. I have tested all the changes and I cant seem to get a confirmation sent to the subscribing user, I also need to change the format so the client receives the information in HTML and not TXT. Example BelowFirst Name: *********Last Name: *********Company: *********Telephone Number: ********* I also need to add in a line that sends the subscribing user (once the form is submitted) product information and pricing, either in HTML or PDF format. Any assistance would greatly be appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/283215-html-online-form-post-to-php/#findComment-1456844 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.