Jump to content

feedback form mail


portia

Recommended Posts

Hi,

I'm playing with a feedback form that needs to be email to an email address.

I'm running it on an apache webserver on CentOS.

 

The relevant bit of index.php is as follows:

<form method="post" action="sendmail.php">
  Email: <input name="email" type="text" /><br />
  Message:<br />
  <textarea name="message" rows="15" cols="40">
  </textarea><br />
  <input type="submit" />
</form>

 

The contents of  the sendmail.php file:

 

<?php
  $email = $_REQUEST['email'] ;
  $message = $_REQUEST['message'] ;

  mail( "yourname@example.com", "Feedback Form Results",
    $message, "From: $email" );
  header( "Location: http://www.example.com/thankyou.html" );
?>

 

I changed the email address to my gmail account, but it doesn't seem to email any feedback.

The sendmail.php script gets executed as after I click on the submit button, I get redirected to example.com/thankyou.html (It doesn't exist, but it doesn't matter)

As you can see I'm a php newbie. Can you tell me what I'm doing wrong.

 

thank you for your time.

 

Link to comment
Share on other sites

NOOB myself, but had a similar problem in the past. You could try something like:

 

if(mail( "yourname@example.com", "Feedback Form Results", $message, "From: $email" ))
             {
                   header( "Location: http://www.example.com/thankyou.html" ); 
             } 
else
            {
                   header( "Location: http://www.example.com/oops.html" );
             } 

 

At least this would tell you if the mail was sent to the cue or not. If it is not sent, make sure the from header is specified in the php.ini (or specify the header in your code).

Link to comment
Share on other sites

The From: email address must be a valid mail box at the sending mail server. If you want to put the entered email address in as a Reply-to: address so that it is easy to send back an email, you must add a Reply-to: header.

 

You must also validate all entered data that is put into the header to avoid header injection that would let a hacker send his email through your mail server, eventually getting it banned by all the major ISP's.

Link to comment
Share on other sites

Thanks for your replies. I knew it's not going to be that easy :(

make sure the from header is specified in the php.ini (or specify the header in your code).

 

Ok, I am not sure what you mean. I have not modified my php.ini in any way.

 

The From: email address must be a valid mail box at the sending mail server.

I don't run a mail server on that computer. Do I really have to do so in order to use php to send emails?:(

I really suspected that it's too good to be true:)

You must also validate all entered data that is put into the header to avoid header injection that would let a hacker send his email through your mail server, eventually getting it banned by all the major ISP's.

 

I have no idea how to do it, but I guess it's not a problem at the moment. The most important thing is to get it up and running.

It's a server running in a virtual machine. I haven't linked any domain to it yet (it's just: http://localhost at the moment)

Link to comment
Share on other sites

I changed the email address to my gmail account

 

Which email address? The To: address or the From: address?

 

I'll guess you meant the To: address, i.e. you want to sent this to your gmail address.

 

You will need to use SMTP authentication (provide you username and password for the receiving mail box) in order to do this in order to get the gmail mail server to accept the emails, which the php mail() function does not support. You would need to either open a socket to the gmail mail server and send it the necessary STMP commands or you can use one of the existing php mailer scripts that will do this for you, such as phpmailer - http://phpmailer.worxware.com/

 

You will pick setting for the script that make it mimic an email client, such as outlook. There are tutorials posted all over the Internet that show how to use phpmiler to send to your mail box at the major ISP's.

Link to comment
Share on other sites

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.