asana Posted February 12, 2013 Share Posted February 12, 2013 (edited) I need help on navigating to a new web page after sending an email from a PHP function. My situation: I have a short form on an HTML page with a "submit" button. Clicking the submit button calls a PHP function that builds and sends the form data in an email. This is working just fine. Currently, after sending the email, the function displays an alert to the effect "Form data has been submitted." I want to change this so that instead of sending the alert, control is transferred to a new HTML page. I've tried the "header/Location" command, but apparently that won't work in this situation. How can I navigate to a new page after sending the email? Pertinent code of the function is as follows: if (strlen($fromName) && strlen($fromAddress) && strlen($videoID) && strlen($preroll) && strlen($postroll)) { $bodyHTML = '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type"><link rel="stylesheet" type="text/css" href="http://www.myurl.com...s"></head><body bgcolor="#ffffff" text="#000000"><div class="emailContentDIV">' .$bodyTextHTML . '</div></body></html>'; SendEmail($toName, $toAddress, $fromName, $fromAddress, $subject, $bodyText, $bodyHTML); (here is where I want to navigate to a new HTML page, after sending the email above) } else { WriteCommand("alert('All fields must contain valid data.');"); } Edited February 12, 2013 by asana Quote Link to comment https://forums.phpfreaks.com/topic/274394-navigate-to-new-html-page-after-sending-email/ Share on other sites More sharing options...
MDCode Posted February 12, 2013 Share Posted February 12, 2013 (edited) Header After a header always use: Die or Exit I don't see how this wouldn't work in this situation as you aren't actually using any html (that you posted). Pertinent code doesn't always work as you aren't clearly stating where this is located and how you are using it. Edited February 12, 2013 by SocialCloud Quote Link to comment https://forums.phpfreaks.com/topic/274394-navigate-to-new-html-page-after-sending-email/#findComment-1411960 Share on other sites More sharing options...
budimir Posted February 12, 2013 Share Posted February 12, 2013 you can use something like header(Location:"wanted_web_page.html"); exit; Quote Link to comment https://forums.phpfreaks.com/topic/274394-navigate-to-new-html-page-after-sending-email/#findComment-1411983 Share on other sites More sharing options...
asana Posted February 12, 2013 Author Share Posted February 12, 2013 Well, here's the full function that's throwing the error (just replaced the real URL with a dummy one). After clicking the "Submit" button on the HTML page, I get an "Error on page" message: <?php $toName = ''; $subject = $_REQUEST['emailSubject']; $fromName = $_REQUEST['custName']; $fromAddress = $_REQUEST['emailAddressFrom']; $videoID = $_REQUEST['videoID']; $preroll = $_REQUEST['preroll']; $postroll = $_REQUEST['postroll']; $toAddress = 'orders@myurl.com'; $bodyText = stripslashes($_REQUEST['emailBody']); $bodyTextHTML = $bodyText; $bodyHTML; $linkTargets = array(); $linkTargets[] = '(http://www.myurl.com)'; $linkTargets[] = '(http://myurl.com)'; $linkTargets[] = '(www.myurl.com)'; $linkTargets[] = '(myurl.com)'; $linkPre = ' <a href="http://www.myurl.com">'; $linkPost = '</a>'; $tLinkString = ""; $tLinkTarget = ""; $bodyTextHTML = ereg_replace(implode('|', $linkTargets), $linkPre . 'http://www.myurl.com' . $linkPost, $bodyTextHTML); $bodyTextHTML = str_replace("\n", '<br />' . "\n", $bodyTextHTML); if (strlen($fromName) && strlen($fromAddress) && strlen($videoID) && strlen($preroll) && strlen($postroll)) { $bodyHTML = '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type"><link rel="stylesheet" type="text/css" href="http://www.myurl.com/pwstylemail.css"></head><body bgcolor="#ffffff" text="#000000"><div class="emailContentDIV">' . $bodyTextHTML . '</div></body></html>'; SendEmail($toName, $toAddress, $fromName, $fromAddress, $subject, $bodyText, $bodyHTML); header('Location: http://www.myurl.com/testit.shtml'); exit; } else { WriteCommand("alert('All fields must contain valid data.');"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/274394-navigate-to-new-html-page-after-sending-email/#findComment-1411984 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.