Jump to content

Recommended Posts

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!

 

Link to comment
https://forums.phpfreaks.com/topic/228452-help-with-an-email-script/
Share on other sites

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>

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?

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

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?

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

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()

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.