php mail() function problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hairytea
Forum Commoner
Posts: 92
Joined: Mon Feb 04, 2008 8:31 am

php mail() function problem

Post by hairytea »

Quick question....

(Probably something very obvious i have overlooked)....

i have writen a script to request variables from my contact form, add them to a string and post them to my email address.

The script works ok in the sense that it posts all info requested from the contact form!

The problem...

The email is set to print like this...

Name: (USER INPUT)
email: (USER INPUT)

etc etc..

i get this printed to the email....

Name: <TEXTFORMAT LEADING=\"2\"><P ALIGN=\"LEFT\"><FONT FACE=\"Arial\" SIZE=\"14\" COLOR=\"#000000\" LETTERSPACING=\"0\" KERNING=\"0\"></FONT></P></TEXTFORMAT><TEXTFORMAT LEADING=\"2\"><P ALIGN=\"LEFT\"><FONT FACE=\"Arial\" SIZE=\"14\" COLOR=\"#000000\" LETTERSPACING=\"0\" KERNING=\"0\">USER INPUT</FONT></P></TEXTFORMAT>

Doeas anyone know why it is printing html as well as the user input? and what can i do to stop this?
coder500
Forum Newbie
Posts: 20
Joined: Fri Jul 25, 2008 10:24 am
Location: Singapore

Re: php mail() function problem

Post by coder500 »

Can you post the code you are using?
User avatar
The_Anomaly
Forum Contributor
Posts: 196
Joined: Fri Aug 08, 2008 4:56 pm
Location: Tirana, Albania

Re: php mail() function problem

Post by The_Anomaly »

hairytea wrote:Quick question....

(Probably something very obvious i have overlooked)....

i have writen a script to request variables from my contact form, add them to a string and post them to my email address.

The script works ok in the sense that it posts all info requested from the contact form!

The problem...

The email is set to print like this...

Name: (USER INPUT)
email: (USER INPUT)

etc etc..

i get this printed to the email....

Name: <TEXTFORMAT LEADING=\"2\"><P ALIGN=\"LEFT\"><FONT FACE=\"Arial\" SIZE=\"14\" COLOR=\"#000000\" LETTERSPACING=\"0\" KERNING=\"0\"></FONT></P></TEXTFORMAT><TEXTFORMAT LEADING=\"2\"><P ALIGN=\"LEFT\"><FONT FACE=\"Arial\" SIZE=\"14\" COLOR=\"#000000\" LETTERSPACING=\"0\" KERNING=\"0\">USER INPUT</FONT></P></TEXTFORMAT>

Doeas anyone know why it is printing html as well as the user input? and what can i do to stop this?
I haven't messed with mail in a while, but IIRC, you need to screw around with the headers. Check out this thread that I got as the first result of a simple google query.
hairytea
Forum Commoner
Posts: 92
Joined: Mon Feb 04, 2008 8:31 am

Re: php mail() function problem

Post by hairytea »

Thank you but that didnt work for me.

I copied the code from that page, changed the to and from fields etc and no joy!

Here is my code...

Code: Select all

 
<?php
  $yourname = $_REQUEST['yourname'];
  $company = $_REQUEST['company'];
  $email = $_REQUEST['email'] ;
  $address= $_REQUEST['address'];
  $bp1 = $_REQUEST['bp1'];
  $bp2 = $_REQUEST['bp2'];
  $bp3 = $_REQUEST['bp3'];
  $bp4 = $_REQUEST['bp4'];
  $bp5 = $_REQUEST['bp5'];
  $incentive = $_REQUEST['incentive'];
  $motto = $_REQUEST['motto'];
  $weburl = $_REQUEST['weburl'];
  $fullpage = $_REQUEST['fullpage'];
 
  $string = "Name:             ".$yourname."\n";
  $string .= "Company Name:    ".$company."\n";
  $string .= "E-Mail:          ".$email."\n";
  $string .= "Address:         ".$address."\n";
  $string .= "Bullet Point 1:  ".$bp1."\n";
  $string .= "Bullet Point 2:  ".$bp2."\n";
  $string .= "Bullet Point 3:  ".$bp3."\n";
  $string .= "Bullet Point 4:  ".$bp4."\n";
  $string .= "Bullet Point 5:  ".$bp5."\n";
  $string .= "Incentive:       ".$incentive."\n";
  $string .= "Motto:           ".$motto."\n";
  $string .= "Website URL:     ".$weburl."\n";
 
 
    mail("root@XXX.co.uk", "Website Request Form", $string, "Your website contact form has been used...", "-froot@XXX.co.uk");
    header( "Location: http://www.XXX.co.uk/thankyou.htm" );
?>
 
FYI:

i have this code (almost the same) working on another website i have made and works absolutely fine....

Code: Select all

 
$email = $_REQUEST['email'] ;
  $message = $_REQUEST['message'] ;
  $name = $_REQUEST['name'] ;
 
  $string = "Name:       ".$name."\n";
  $string .= "E-Mail:      ".$email."\n";
  $string .= "Message:   ".$message;
 
  if (empty($email) || empty($message) || empty($name)) {
    header( "Location: http://www.XXX.co.uk/error.html" );
  }
  else {
    mail("root@XXXco.uk", "Website Request Form", $string, "Your website contact form has been used...", "-froot@XXX.co.uk");
    header( "Location: http://www.XXX.co.uk/thankyou.html" );
 
Just to recap...

When email is received from the website i get this printed in the email body....

Name: <TEXTFORMAT LEADING=\"2\"><P ALIGN=\"LEFT\"><FONT FACE=\"Arial\" SIZE=\"14\" COLOR=\"#000000\" LETTERSPACING=\"0\" KERNING=\"0\">lknlkn</FONT></P></TEXTFORMAT>
Company Name: <TEXTFORMAT LEADING=\"2\"><P ALIGN=\"LEFT\"><FONT FACE=\"Arial\" SIZE=\"14\" COLOR=\"#000000\" LETTERSPACING=\"0\" KERNING=\"0\">lknlknlkn</FONT></P></TEXTFORMAT>


as opposed to the second script i posted when it prints like this in the email body....

Name: User Input
E-Mail: User Input

Now, as far as i can see the only difference between the 2 scripts is that the latter uses an if else clause to checkj if the fields are empty or not whereas the first script i posted does not as i am using javascript to check the input before submitting?
hairytea
Forum Commoner
Posts: 92
Joined: Mon Feb 04, 2008 8:31 am

Re: php mail() function problem

Post by hairytea »

I hope is ok to do this....i am editing this post purely to bring to the top of the list again as has been pushed down by someone spamming the forum and constantly posting his web address.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: php mail() function problem

Post by Jonah Bron »

Unless I've gone completely crazy, I don't think this is right:

Code: Select all

mail("root@XXX.co.uk", "Website Request Form", $string, "Your website contact form has been used...", "-froot@XXX.co.uk");
I think that it should be this:

Code: Select all

mail('root@XXX.co.uk', 'Website Request Form', $string, 'From: root@XXX.co.uk');
What was the ..."Your website contact form has been used..."... part? The first argument is To, second, Subject, third, Body, Fourth, Headers, etc. If you want that little note in the Body, then it should be

Code: Select all

mail('root@XXX.co.uk', 'Website Request Form', 'Your website contact form has been used...'."\n".$string, 'From: root@XXX.co.uk');
Pardon me if I've lost my mind :)
Post Reply