+ Reply to Thread
Results 1 to 6 of 6

Thread: HTML email via PHP appears to be working.....but it's not???

  1. #1
    jcarlin14 is offline x10Hosting Member jcarlin14 is an unknown quantity at this point
    Join Date
    Feb 2011
    Posts
    3

    HTML email via PHP appears to be working.....but it's not???

    Hi,

    I am attempting to send a HTML email via PHP using coding that i know works. It submits the contents of a form to a DB before emailing the results. Here is the coding...

    <?php
    $var1 = $_POST['var1'];
    $var2 = $_POST['var2'];
    $var3 =$_POST['var3'];
    $var4 = $_POST['var4'];
    $var5 = $_POST['var5'];
    $var6 = $_POST['var6'];
    $var7 = $_POST['var7'];
    $var8 = $_POST['var8'];
    $to = "email@email";
    $from = "test";
    $subject = "you have recieved an email from" .$_POST['var3'];
    $headers = "MIME-Version: 1.0rn";
    $headers .= "Content-type: text/html; charset=iso-8859-1rn";
    $headers .= "From: $from\r\n";

    $message="
    <html>
    <body>
    <center>
    <b>Here is the email you have sent</b> <br>
    </center>
    <p>it's been sent</p>
    </body>
    </html>";

    mysql_connect("localhost","username","password") or die ('Error: ' . mysql_error());
    mysql_select_db ('dbname');

    $query="INSERT INTO resultslog(var1, var2, var3, var4, var5, var6, var7, var VALUES ('".$var1."','".$var2"','".$var3."','".$var4."','" .$var5."','".$var6."','".$var7."','".$var8."')";
    mysql_query($query) or die (mysql_error());
    if (mail($to,$subject,$message,$headers) ) {
    ECHO "Your message has been sent";
    }else{
    ECHO "The email has failed";
    }
    ?>

    When I submit the form I am presented with the "Your message has been sent" text and the data is submitted to the DB but the email is not being sent? Does anyone have any idea why this might not be happening?

    Thanks,

    JC

  2. #2
    ice.adi49 is offline x10Hosting Member ice.adi49 is an unknown quantity at this point
    Join Date
    Nov 2010
    Posts
    8

    Re: HTML email via PHP appears to be working.....but it's not???

    probably is because of the headers (you
    try:
    Code:
    $headers = "MIME-Version: 1.0\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1\n";
    $headers .= "From: $from \n";
    if this fails too, then it could be that you are not allowed to send mails on that server.
    Happen to me on a godaddy hosting, when in order to send mail, i had to access a smtp which required authentication.

  3. #3
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: HTML email via PHP appears to be working.....but it's not???

    Please use [php], [html] or [code] tags (as appropriate) to separate and format code.

    Quote Originally Posted by jcarlin14 View Post
    PHP Code:
    <?php
    $var1 
    $_POST['var1'];
    $var2 $_POST['var2'];
    [...]
    I hope you've renamed these variables out of concern for security. Otherwise, you should always use descriptive variable names so your code is readable (and security through obscurity doesn't work).

    Quote Originally Posted by jcarlin14 View Post
    PHP Code:
    $query="INSERT INTO resultslog(var1, var2, var3, var4, var5, var6, var7, var8) VALUES ('".$var1."','".$var2"','".$var3."','".$var4."','".$var5."','".$var6."','".$var7."','".$var8."')"
    This is vulnerable to SQL injection, which is a very serious security risk. To fix this hole, switch from the outdated mysql driver to PDO and use prepared statements. If you need a PDO tutorial, try "Writing MySQL Scripts with PHP and PDO". The site you save may just be your own.

    Quote Originally Posted by jcarlin14 View Post
    PHP Code:
    mysql_query($query) or die (mysql_error()); 
    Don't use die when outputting HTML.

    Outputting the result of mysql_error to non-admin users discloses too much information.

    Quote Originally Posted by jcarlin14 View Post
    When I submit the form I am presented with the "Your message has been sent" text and the data is submitted to the DB but the email is not being sent[.]
    mail returns true if the message is accepted delivery, not for if it's delivered.

    How do you know it's not being delivered? Have you checked your spam folder?
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  4. #4
    jcarlin14 is offline x10Hosting Member jcarlin14 is an unknown quantity at this point
    Join Date
    Feb 2011
    Posts
    3

    Re: HTML email via PHP appears to be working.....but it's not???

    Hi,

    Thanks for the responses. I have checked Spam folder and also tried sending to different email addresses. I have changed the variable names, just want to get it working before I set everything correctly.

    I have also sent non-HTML emails and they are working fine, which is what is confusing me?

    Thanks,

    JC

  5. #5
    ricky315 is offline x10Hosting Member ricky315 is an unknown quantity at this point
    Join Date
    Mar 2011
    Posts
    1

    Re: HTML email via PHP appears to be working.....but it's not???

    I'm sure that there are HTML error that's why you can't send your email. I suggest you use HTML email checkers to find out the problem

  6. #6
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: HTML email via PHP appears to be working.....but it's not???

    Doubtful. With the Internet Message Format, it doesn't much matter whether message content is properly structured for its content type as long as it's properly escaped so as not to interfere with the MIME format. The sample doesn't even make use of multipart messages, so there's nothing to worry about on that front. Message content has even less of an impact in SMTP. If the HTML were invalid. the e-mail should still be delivered.

+ Reply to Thread

Similar Threads

  1. PHP AND HTML Email Script Help
    By mattblog in forum Programming Help
    Replies: 4
    Last Post: 08-03-2010, 02:55 PM
  2. Replies: 2
    Last Post: 02-22-2010, 02:22 PM
  3. Replies: 3
    Last Post: 02-11-2010, 02:09 PM
  4. HTML Form Email
    By bpakidz in forum Programming Help
    Replies: 6
    Last Post: 09-01-2008, 11:55 AM
  5. HTML Form to email?
    By verticalnfinity in forum Programming Help
    Replies: 9
    Last Post: 09-01-2008, 11:36 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers