timothyarden Posted October 5, 2012 Share Posted October 5, 2012 Hi PHP Freaks, I am currently having trouble with my mailing script. When I load it in the browser it comes up with the following error: 500 Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator, webmaster@domain-name.com and inform them of the time the error occurred, and anything you might have done that may have caused the error. More information about this error may be available in the server error log. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request. There is no errors in the error_log and in the email failure email sent to my webmaster email it says it contained no recipient address but I have set that in the code. Here is the Code HTML Form: <form method="post" action="mail.php"> <label for="firstname">Firstname:</label> <input type="text" name="firstname" id="firstname" value="" /> <label for="lastname">Lastname:</label> <input type="text" name="lastname" id="lastname" value="" /> <label for="email_address">Email Address:</label> <input type="text" name="email_address" id="email_address" value="" /> <label for="subject">Subject:</label> <select name="subject" id="subject"> <option name="request_appointment" id="request_appointment" value="Request an Appointment">Request an Appointment</option> <option name="request_callback" id="request_callback" value="Request a Call-Back">Request a Call-Back</option> <option name="question" id="question" value="I Have a Question">I Have a Question</option> <option name="emergency" id="emergency" value="Emergency">Emergency (Call 0422 036 768)</option> <option name="other" id="other" value="Other">Other</option> </select><br /> <label for="message">Message:</label> <textarea name="message" id="message" cols="45" rows="10"></textarea> <button type="submit" value="submit"><span>Submit</span></button> </form> PHP Scripting <?php //declare variables $email_successful_page = 'mail_successful.php'; //create mail_successful.php; $email_failed_page = 'delivery_failed.php'; //create delivery_failed.php; //create emailform.php (and in it the ability to read the error from this script and tell the user //declare email variables $firstname = ucwords(strtolower($_REQUEST['firstname'])); $lastname = ucwords(strtolower($_REQUEST['lastname'])); $subject = $_POST['subject']; $message = wordwrap($_POST['message'], 150, '<br />'); $client_name = $firstname." ".$lastname; $dentist_name = $_REQUEST['dentist']; $dentist_email = $dentist_name.'@domain-name.com.au'; $client_email = $_POST['email_address']; //date date_default_timezone_set('Australia/NSW'); global $email_1_recipient_address, $email_1_subject, $email_1_message, $email_1_headers, $email_2_recipient_address, $email_2_subject, $email_2_message, $email_2_headers, $email_3_recipient_address, $email_3_subject, $email_3_message, $email_3_headers; //email 1 is sent to the scd admin email $email_1_recipient_address = 'systemadministrator@domain-name.com.au'; $email_1_subject = 'Email sent to '.$dentist_name.' from '.$client_email.' regarding '.$subject; $email_1_message = '<html>\n\t<body>\n\t\t<img src=\"emailheader.jpg\" width="" height="" style="float:center;"/>\n\t\t'; $email_1_message .= '\n\t\t<h1>Hi System Administrator, </h1>'; $email_1_message .= '\n\t\t<br /><p>For records, </p>'; $email_1_message .= ''; $email_1_message .= ''; $email_1_headers = "From: autoresponder@domain-name.com.au \r\n"; $email_1_headers .= "Reply-To: donotreply@domain-name.com.au \r\n"; $email_1_headers .= "X-Mailer: PHP/".phpversion()." \r\n"; $email_1_headers .= "To: joshua.paduch@gmail.com \r\n"; $email_1_headers .= "Content-type: text/html; charset=UTF-8 \r\n"; $email_1_headers .= "MIME-Version: 1.0 \r\n"; //$email_1_headers .= " \r\n"; //email 2 is sent to the intended dentist / practitioner $email_2_recipient_address = 'info@domain-name.com.au'; $email_2_subject = $subject; $email_2_message = 'message'; $email_2_message .= ''; $email_2_message .= ''; $email_2_headers = "From: autoresponder@domain-name.com.au \r\n"; $email_2_headers .= "Reply-To: donotreply@domain-name.com.au \r\n"; $email_2_headers .= "X-Mailer: PHP/".phpversion()." \r\n"; $email_2_headers .= "To: joshua.paduch@gmail.com \r\n"; $email_2_headers .= "Content-type: text/html; charset=UTF-8 \r\n"; $email_2_headers .= "MIME-Version: 1.0 \r\n"; //$email_2_headers .= " \r\n"; //email 3 is a confirmation email sent to the client $email_3_recipient_address = $client_email; $email_3_subject = 'Confirmation Email Regarding: '.$subject; $email_3_message = 'message'; $email_3_message .= ''; $email_3_message .= ''; $email_3_headers = "From: autoresponder@domain-name.com.au \r\n"; $email_3_headers .= "Reply-To: donotreply@domain-name.com.au \r\n"; $email_3_headers .= "X-Mailer: PHP/".phpversion()." \r\n"; $email_3_headers .= "To: ".$client_email." \r\n"; $email_3_headers .= "Content-type: text/html; charset=UTF-8 \r\n"; $email_3_headers .= "MIME-Version: 1.0 \r\n"; //$email_3_headers .= " \r\n"; //validate inputs function form_validation(){ function email_address_validation(){ //Validates & Sanitizes the email address if(!filter_var($client_email, FILTER_VALIDATE_EMAIL) && strlen($client_email) < 1){ global $error; global $error_page; $error = "Email Address was empty or had a invalid value."; $error_page = "email address error"; return true; } else{ return false; } } function firstname_validation(){ if(strlen($firstname) > 0){ global $error; global $error_page; $error = "Firstname was empty or had a invalid value."; $error_page = "firstname error"; return true; } else{ return false; } } function lastname_validation(){ if(strlen($lastname) > 0){ global $error; global $error_page; $error = "Lastname was empty or had a invalid value."; $error_page = "lastname error"; return true; } else{ return false; } } function subject_validation(){ if(!isset($subject)){ global $error; global $error_page; $error = "Subject was empty or had a invalid value."; $error_page = "subject error"; return true; } else{ return false; } } function message_validation(){ if(!isset($message)){ global $error; global $error_page; $error = "Message was empty or had a invalid value."; $error_page = "message content error"; return true; } else{ return false; } } //call to above validation function to be executed when form_validation is called global $email_address_validation, $firstname_validation, $lastname_validation, $subject_validation, $message_validation; $email_address_validation = email_address_validation(); $firstname_validation = firstname_validation(); $lastname_validation = lastname_validation(); $subject_validation = subject_validation(); $message_validation = message_validation(); if(!isset($error) || $email_address_validation == false || $firstname_validation == false || $lastname_validation == false || $subject_validation == false || $message_validation == false){ return true; } else{ return false; } } $form_validation = form_validation(); //if the form validation returns false - break the code - write the error and contact form to page if($form_validation != true){ header($email_failed_page); break; //check to see this breaks the entire script not just the if loop } //declare email functions function send_emails(){ /* mail($email_1_recipient_address, $email_1_subject, $email_1_message, $email_1_headers); mail($email_2_recipient_address, $email_2_subject, $email_2_message, $email_2_headers); mail($email_3_recipient_address, $email_3_subject, $email_3_message, $email_3_headers); */ if(mail($email_1_recipient_address, $email_1_subject, $email_1_message, $email_1_headers) && mail($email_2_recipient_address, $email_2_subject, $email_2_message, $email_2_headers) && mail($email_3_recipient_address, $email_3_subject, $email_3_message, $email_3_headers)){ header($email_sucessful_page); } else{ header($email_failed_page.'?error='.urlencode(htmlentities($error_page))); //add in read error from $_GET } } $send_emails = send_emails(); if(!$send_emails){ header($email_failed_page.'?error='.urlencode(htmlentities($error_page))); } else{ header($email_sucessful_page); } ?> Any ideas or comments are welcome. Thanks in advance guys, Timothy Call Send SMS Add to Skype You'll need Skype CreditFree via Skype Quote Link to comment https://forums.phpfreaks.com/topic/269110-mail-problems/ Share on other sites More sharing options...
seanlim Posted October 5, 2012 Share Posted October 5, 2012 For a start, I think the header redirects need to be of the format: header("Location: /path/to/file.php"); You seem to be missing the "Location: " bit. Quote Link to comment https://forums.phpfreaks.com/topic/269110-mail-problems/#findComment-1382847 Share on other sites More sharing options...
timothyarden Posted October 6, 2012 Author Share Posted October 6, 2012 Thanks, Totally missed that. Quote Link to comment https://forums.phpfreaks.com/topic/269110-mail-problems/#findComment-1383126 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.