smokekills Posted February 22, 2011 Share Posted February 22, 2011 Alright, so here's the problem. I am trying to code up a PHP script that basically sends an email. Sounds basic, right? Here's the tricky part. Using HTML or any other code will simply just load your default mail client and try to send it with that, what I need is a script that sends it via my website. I'll try to explain, Name: (This will send me their name they type) Email: (Same as above) Submit: (This will be the button they press when they submit the fore-mentioned details.) What would need to happen is the PHP would need to include the data entered in the name, and email field, (after the user clicks the submit button) copy it, and paste it into a email that is sent to my email address. (My email needs to be hidden obviously) But this needs to be done server side, without opening the person's mail client. And then once the email is sent, they need to be re-directed to a page. Only problem is, I CANNOT code PHP to save my life, I know this script is possible I've had it done before but lost the script :'( Much appreciated anyone who can help me out on this one! Quote Link to comment https://forums.phpfreaks.com/topic/228452-help-with-an-email-script/ Share on other sites More sharing options...
.josh Posted February 22, 2011 Share Posted February 22, 2011 super simple example: <?php if ($_POST) { if ($_POST['from']&&$_POST['subject']&&$_POST['message']) { $to = 'your email address here'; $redirect = 'url to redirect here'; mail ($to, $_POST['from'] , $_POST['message']) ; header('Location: '.$redirect); exit(); } else { echo "you need to fill out all of the fields in the form!</br>"; } } ?> <form name='contact' method='post' action=''> From: <input type='text' name='from' /><br/> Subject: <input type='text name='subject' /><br/> Message: <textarea name='message' cols='20 rows='10'></textarea><br/> <input type='submit' name='submit' value='email!' /> </form> Quote Link to comment https://forums.phpfreaks.com/topic/228452-help-with-an-email-script/#findComment-1178006 Share on other sites More sharing options...
smokekills Posted February 23, 2011 Author Share Posted February 23, 2011 super simple example: <?php if ($_POST) { if ($_POST['from']&&$_POST['subject']&&$_POST['message']) { $to = 'your email address here'; $redirect = 'url to redirect here'; mail ($to, $_POST['from'] , $_POST['message']) ; header('Location: '.$redirect); exit(); } else { echo "you need to fill out all of the fields in the form!</br>"; } } ?> <form name='contact' method='post' action=''> From: <input type='text' name='from' /><br/> Subject: <input type='text name='subject' /><br/> Message: <textarea name='message' cols='20 rows='10'></textarea><br/> <input type='submit' name='submit' value='email!' /> </form> Thanks for taking time to help me, I went to test that script you provided and it just keeps saying "you need to fill out all of the fields in the form!" without actually sending anything no matter what I do. How do I fix that error? Quote Link to comment https://forums.phpfreaks.com/topic/228452-help-with-an-email-script/#findComment-1178436 Share on other sites More sharing options...
.josh Posted February 23, 2011 Share Posted February 23, 2011 there was a small typo in the form. Was missing a closing quote (marked below as giant and blue): Subject: <input type='text' name='subject' /><br/> Quote Link to comment https://forums.phpfreaks.com/topic/228452-help-with-an-email-script/#findComment-1178442 Share on other sites More sharing options...
smokekills Posted February 23, 2011 Author Share Posted February 23, 2011 there was a small typo in the form. Was missing a closing quote (marked below as giant and blue): Subject: <input type='text' name='subject' /><br/> ah! Fixed that, now it seems to be working but then it looks like the script re-directs my browser and I come to this. The file or folder you've requested could not be found. Please check the URL and try again. Idk if the redirection is broken or what, also, emails are not being sent :\ thanks for the help Quote Link to comment https://forums.phpfreaks.com/topic/228452-help-with-an-email-script/#findComment-1178444 Share on other sites More sharing options...
.josh Posted February 23, 2011 Share Posted February 23, 2011 well did you actually change these 2 lines: $to = 'your email address here'; $redirect = 'url to redirect here'; to be the right values? Quote Link to comment https://forums.phpfreaks.com/topic/228452-help-with-an-email-script/#findComment-1178447 Share on other sites More sharing options...
smokekills Posted February 23, 2011 Author Share Posted February 23, 2011 yessir, double checked even. I'm not too worried about the re-direction not working I'm just more concerned about it actually sending a email :\ Quote Link to comment https://forums.phpfreaks.com/topic/228452-help-with-an-email-script/#findComment-1178448 Share on other sites More sharing options...
.josh Posted February 23, 2011 Share Posted February 23, 2011 As far as the redirect: The only reason it would give that error is if the url you entered in for $redirect doesn't exist. That's what the error is telling you, that you are trying to request a page that doesn't exist. So you must have typoed the url or not using the correct path (or the page like..doesn't exist). As far as no email... What email address did you send it to? A lot of email providers like yahoo, gmail, etc... like to mark stuff as spam/junk...did you check your spam/junk/trash or any other email filter(s) you may have setup? Are you testing this on your own computer using WAMP or something, or are you testing this on a website somewhere with a mail server setup? Quote Link to comment https://forums.phpfreaks.com/topic/228452-help-with-an-email-script/#findComment-1178452 Share on other sites More sharing options...
smokekills Posted February 23, 2011 Author Share Posted February 23, 2011 I'm using a gmail account, I checked junk, and everything, still no emails. And I'm testing this on a website, but what do you mean about the mail server setup? I just have the script saved as test.php and I keep testing it but I keep getting the same problems. Should I make a new email with a new host or simply just pay for better hosting? Like blue host or something. Because I'm using ripway Quote Link to comment https://forums.phpfreaks.com/topic/228452-help-with-an-email-script/#findComment-1178455 Share on other sites More sharing options...
.josh Posted February 23, 2011 Share Posted February 23, 2011 okay well it's possible that your host may not allow the mail() function to be used... in order for the mail() function to work, it needs to be mapped to a mail server. A lot of super cheap/free hosts do not allow this (they disable it) because it allows for spammers to go crazy. I suggest you talk to your hosting provider and find out if they support mail() Quote Link to comment https://forums.phpfreaks.com/topic/228452-help-with-an-email-script/#findComment-1178461 Share on other sites More sharing options...
smokekills Posted February 23, 2011 Author Share Posted February 23, 2011 is there a cheap/free hosting service you happen to know of that does allow mail()? Also, 1 mail did get through, but thats it. I sent atleast 20 test emails but I only recieved 1. What could be causing this? Quote Link to comment https://forums.phpfreaks.com/topic/228452-help-with-an-email-script/#findComment-1178463 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.