thinktec Posted September 3, 2009 Share Posted September 3, 2009 Here's the situation... This PHP form I'm using on this page is not working (it's on a Yahoo server)... http://www.turnofthedecade.com/rsvp.php When I put that same form on my personal server (which is hosted with gate.com) it works just fine and I receive the confirmation email and everything. Can anyone tell me what's going on here? I read in Yahoo's documentation that they require all outgoing emails with PHP to be sent from an email address within your domain BUT I already have that setup. I'm stumped... Link to comment https://forums.phpfreaks.com/topic/173023-brain-buster-why-wont-my-php-contact-form-work-on-a-yahoo-server/ Share on other sites More sharing options...
bundyxc Posted September 3, 2009 Share Posted September 3, 2009 I never thought that having Yahoo! hosting would ever be beneficial... but I guess it can come in handy now. haha. Anyway, try setting a reply-to address. Link to comment https://forums.phpfreaks.com/topic/173023-brain-buster-why-wont-my-php-contact-form-work-on-a-yahoo-server/#findComment-911943 Share on other sites More sharing options...
thinktec Posted September 3, 2009 Author Share Posted September 3, 2009 This is the code for my contact-form.php file which processes the form... <div class="contact_form"> <!-- ***** Config ********************************************************** --> <?php $contact_form_msg_clear = 'Clear'; $contact_form_msg_submit = 'Submit'; $contact_form_msg_submit = $contact_form_graph ? '' : $contact_form_msg_submit; $contact_form_msg_sent = 'Thank you for the RSVP.'; $contact_form_msg_not_sent = 'Message not sent. Please try again.'; $contact_form_msg_invalid = 'Please, correct the fields marked in red'; ?> <!-- ***** PHP ************************************************************* --> <?php // ***** contact_form_mail ***** function contact_form_mail($to, $subject, $message, $headers = '', $charset = 'utf-8', $files = array()) { if (!count($files)) { $ext_headers = $headers; $ext_headers .= "Content-Type: text/plain; charset=\"$charset\"\r\n"; $ext_message = $message; } else { $boundary = 'a6cd792e'; while (true) { if (strpos($subject, $boundary) !== false || strpos($message, $boundary) !== false) { $boundary .= dechex(rand(0, 15)) . dechex(rand(0, 15)); continue; } foreach ($files as $fi_name => $fi_data) if (strpos($fi_name, $boundary) !== false || strpos($fi_data, $boundary) !== false) { $boundary .= dechex(rand(0, 15)) . dechex(rand(0, 15)); continue; } break; } $ext_headers = $headers; $ext_headers .= "MIME-Version: 1.0\r\n"; $ext_headers .= "Content-Type: multipart/mixed; boundary=\"$boundary\"\r\n"; $ext_message = "This is a multi-part message in MIME format."; $ext_message .= "\r\n--$boundary\r\n"; $ext_message .= "Content-Type: text/plain; charset=\"$charset\"\r\n\r\n"; $ext_message .= $message; $ext_message .= "\r\n--$boundary\r\n"; foreach ($files as $i => $x) { $ext_message .= "Content-Type: {$x['type']}; name=\"{$x['name']}\"\r\n"; $ext_message .= "Content-Disposition: attachment\r\n"; $ext_message .= "Content-Transfer-Encoding: base64\r\n\r\n"; $ext_message .= chunk_split(base64_encode($x['data'])); $ext_message .= "\r\n--$boundary\r\n"; } } $error_reportings = error_reporting(E_ERROR | E_PARSE); $res = mail($to, $subject, $ext_message, $ext_headers); $error_reportings = error_reporting($error_reportings); return $res; } // ***** contact_form_post ***** function contact_form_post($name) { if (isset($_POST[$name])) return htmlentities($_POST[$name], ENT_COMPAT); if (isset($_GET [$name])) return htmlentities($_GET [$name], ENT_COMPAT); return ''; } // ***** Send Mail ***** if (count($_POST)) { if (get_magic_quotes_gpc() && !function_exists('strip_slashes_deep')) { function strip_slashes_deep($value) { if (is_array($value)) return array_map('strip_slashes_deep', $value); return stripslashes($value); } $_GET = strip_slashes_deep($_GET); $_POST = strip_slashes_deep($_POST); $_COOKIE = strip_slashes_deep($_COOKIE); } $patern_aux1 = "(\\w+(-\\w+)*)"; $patern_aux2 = "($patern_aux1\\.)*$patern_aux1@($patern_aux1\\.)+$patern_aux1"; $ename = ''; $email = ''; $esubj = 'RSVP Confirmation Email'; $ehead = $contact_form_message_prefix; $ebody = ''; $valid = true; foreach ($contact_form_fields as $i => $x) { $_POST[$i] = isset($_POST[$i]) ? $_POST[$i] : ''; if ($x['type'] === 'upload') { if (isset($_POST["$i-clear"]) && $_POST["$i-clear"]) unset($_SESSION['contact-form-upload'][$i]); if (isset($_FILES[$i]) && $_FILES[$i][ 'type'] && $_FILES[$i][ 'name'] && $_FILES[$i]['tmp_name'] && file_exists($_FILES[$i]['tmp_name']) && filesize($_FILES[$i]['tmp_name']) <= $x['maxsize']) $_SESSION['contact-form-upload'][$i] = array('type' => $_FILES[$i][ 'type'], 'name' => $_FILES[$i][ 'name'], 'data' => file_get_contents($_FILES[$i]['tmp_name'])); } if ($x['type'] === 'checkbox' && trim($_POST[$i]) || $x['type'] === 'department' && trim($_POST[$i]) || $x['type'] === 'input' && trim($_POST[$i]) || $x['type'] === 'name' && trim($_POST[$i]) || $x['type'] === 'select' && trim($_POST[$i]) || $x['type'] === 'subject' && trim($_POST[$i]) || $x['type'] === 'textarea' && trim($_POST[$i]) || $x['type'] === 'email' && preg_match("/^$patern_aux2$/sDX", $_POST[$i]) || $x['type'] === 'turing' && isset($_SESSION['contact-form-number']) && $_POST[$i] === $_SESSION['contact-form-number'] || $x['type'] === 'upload' && isset($_SESSION['contact-form-upload'][$i])) { if ( $x['type'] === 'textarea') $ebody .= "\r\n" . $_POST[$i] . "\r\n"; if ( $x['type'] !== 'textarea') if (!$x['name'] && isset($x['prompt'])) $ehead .= $x['prompt'] . ' ' . $_POST[$i] . "\r\n"; else $ehead .= $x['name' ] . ' ' . $_POST[$i] . "\r\n"; } elseif ($x['require'] || $_POST[$i] !== '') { $valid = false; if (!$x['name'] && isset($x['prompt'])) $contact_form_fields[$i]['prompt'] = "<em>{$x['prompt']}</em>"; else $contact_form_fields[$i]['name' ] = "<em>{$x['name' ]}</em>"; } switch ($x['type']) { case 'department': foreach ($x['items'] as $j => $y) if ($y === $_POST[$i]) $contact_form_email = $j; break; case 'email': $email = $_POST[$i]; break; case 'name': $ename = $_POST[$i]; break; case 'subject': $esubj = $_POST[$i]; break; } } if ($valid) { $mail_sent = contact_form_mail($contact_form_email, $esubj, $ehead . $ebody, "To: $contact_form_email\r\nFrom: $ename <$email>\r\n", $contact_form_encoding, isset($_SESSION['contact-form-upload']) ? $_SESSION['contact-form-upload'] : array()); if ($mail_sent) echo '<div class="error"><em>' . $contact_form_msg_sent . '</em></div>'; else echo '<div class="error"><em class="error">' . $contact_form_msg_not_sent . '</em></div>'; if ($mail_sent) $_POST = array(); if ($mail_sent) $_SESSION = array(); } else echo '<div class="error"><em>' . $contact_form_msg_invalid . '</em></div>'; } $_SESSION['contact-form-number'] = str_pad(rand(0, 9999), 4, '0', STR_PAD_LEFT); ?> <!-- ***** HTML ************************************************************ --> <form method="post" action="<?=$_SERVER['REQUEST_URI'];?>" enctype="multipart/form-data"> <table cellpadding="6"> <?php $slash = $contact_form_xhtml ? '/' : ''; foreach ($contact_form_fields as $i => $x) { ?> <tr> <th align="right"><?=$x['name'];?></th> <td> <?php switch ($x['type']) { case 'name': case 'email': case 'input': case 'subject': ?> <div class="input"><input name="<?=$i;?>" type="text" value="<?=contact_form_post($i);?>" <?=$slash;?>></div> <?php break; case 'turing': ?> <div class="input"><input name="<?=$i;?>" type="text" value="<?=contact_form_post($i);?>" <?=$slash;?>></div> <img width="60" height="17" src="<?=$x['url'];?>?sname=<?=session_name();?>&rand=<?=rand();?>" alt="" <?=$slash;?>> <br style="clear: both;" <?=$slash;?>> <small><?=$x['prompt'];?></small> <?php break; case 'upload': ?> <input name="<?=$i;?>" type="file" value="<?=contact_form_post($i);?>" <?=$slash;?>> <?php if (isset($_SESSION['contact-form-upload'][$i])) { ?> <input name="<?=$i;?>-clear" type="checkbox" value="Yes" <?=$slash;?>> <?=$contact_form_msg_clear;?> <?=$_SESSION['contact-form-upload'][$i]['name'];?> <?php } break; case 'checkbox': ?> <input name="<?=$i;?>" type="checkbox" value="Yes" <?=contact_form_post($i) ? 'checked="checked"' : '';?> <?=$slash;?>> <small><?=$x['prompt'];?></small> <?php break; case 'textarea': ?> <div class="input"><textarea name="<?=$i;?>" cols="45" rows="6"><?=contact_form_post($i);?></textarea></div> <?php break; case 'select': case 'department': ?> <select name="<?=$i;?>"> <option value=""><?=$x['default'];?></option> <?php foreach ($x['items'] as $j => $y) { ?><option value="<?=$y;?>" <?=contact_form_post($i) === $y ? 'selected="selected"' : '';?>><?=$y;?></option><?php } ?> </select> <?php break; } ?> </td> </tr> <?php } ?> <tr><th></th><td><input id="submit_contact" class="submit" type="submit" value="<?=$contact_form_msg_submit;?>" <?=$slash;?>></td></tr> </table> </form> </div> And this is the code that you insert on the page with the contact form... <?php $contact_form_fields = array( array('name' => 'Name (first and last):', 'type' => 'name', 'require' => 1), array('name' => 'I will attend:', 'type' => 'select', 'require' => 1, 'default' => '-', 'items' => array('Yes', 'No')), array('name' => 'My spouse or guest will attend:', 'type' => 'select', 'require' => 1, 'default' => '-', 'items' => array('Yes', 'No')), array('name' => 'I plan to book at the Cypress Hotel:', 'type' => 'select', 'require' => 1, 'default' => '-', 'items' => array('Yes', 'No', 'Maybe')), array('name' => 'E-mail Address:', 'type' => 'email', 'require' => 1), array('name' => 'Mobile Phone:', 'type' => 'input', 'require' => 1)); $contact_form_graph = false; $contact_form_xhtml = true; $contact_form_email = "[email protected]"; $contact_form_encoding = "utf-8"; $contact_form_message_prefix = "RSVP Information\r\n______________________________________________\r\n\r\n"; include_once "contact-form.php"; ?> Link to comment https://forums.phpfreaks.com/topic/173023-brain-buster-why-wont-my-php-contact-form-work-on-a-yahoo-server/#findComment-912043 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.