0

my php email script doesn't seem to be sending but I can't see why. Also I understand that there are certain security flaws with my script, any advice with that is much appreciated!

thank you

  <?php

include('config.php');

$email1 = $_POST['email1'];

$id = $_POST['id'];
$fname = $_POST['fname'];
$firstname = $_POST['firstname'];
$surname = $_POST['surname'];


$to = '$email1';
$from = "$email"; 
    $subject = "SC - You Have a Reply"; 

        $body = "<html> 
  <body bgcolor=\"#FFFFFF\"> 
    <center> 
        <b>Dear $firstname</b> <br> 
        <font color=\"red\">You have a response, regarding your Ad on StudentClutter!</font> <br>
         <p> --------------------------------------------------------- </p>
         <b> $fname </b>
         <p> --------------------------------------------------------- </p>
         <p> ".stripslashes($_POST['body'])." </p>
         <br>
         <br>
         <br>
         <p> You can reply to them by email: $emailadd </p>
         <br>
         <br>
         <br>
         <p>Thank you for using studentclutter.com </p>
         <p> -- The Student Clutter Team </p>
    </center> 
  </body> 
</html>";

    // To send the HTML mail we need to set the Content-type header. 
    $headers = "MIME-Version: 1.0rn"; 
    $headers .= "Content-type: text/html; charset=iso-8859-1rn"; 
    $headers  .= "From: $from\r\n"; 

    // now lets send the email. 
    mail($to, $subject, $body, $headers); 

    echo "Message has been sent!"; 

 ?>
5
  • Are you getting some sort of error? That could help us figure out what's wrong. Commented Dec 17, 2012 at 22:13
  • 1
    Use swiftmailer.org and your problems are gone... Commented Dec 17, 2012 at 22:13
  • @Glavić thankyou that looks like a good solution, any ideas how to use it? Commented Dec 17, 2012 at 22:14
  • Have you at least done some basic debugging to figure out if the values for the variable used in mail() are what you expect them to be? Do you get success returned from mail() but there just isn't an email sent (which might point to system-level email delivery or config problem)? Commented Dec 17, 2012 at 22:16
  • Click documentation in the menu, it is all there... Commented Dec 17, 2012 at 22:17

1 Answer 1

1

You are using single quotes around $email1, these are not necessary. Remove the quotes and it should work just fine.

Like this

$to = $email1;

I would advise you to check out the PHPMailer class, this class offers a whole range of features, along with security. It is very easy to use, just read through the documentation.

UPDATE

You have not escaped the return and new line special characters at the end of some of the headers. Change the end of the lines to look like this:

\r\n";
Sign up to request clarification or add additional context in comments.

4 Comments

thank you so much! the email is now sent, however, any idea why the html isn't displaying?
I haven't had a chance to have a good read through the HTML as I am currently on my iPad and testing code is slightly harder :-). However I would suggest that you check out the class that I have linked to in my answer, this will help you achieve what you want to achieve and will handle all the difficult bits. HTML in emails can cause all sorts of issues if the code is not formatted correctly. It can be as pathetic as adding requiring spaces before closing tags. The class will help you with this
Having said that I can see one issue in your headers code, will post an update to my answer
thank you for all your replies!! I see your update, could you explain where I must change this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.