Jump to content

i need some help with my code, can somebody help fix it so it works?


tankround

Recommended Posts


<?PHP
 
$emailSubject = $_POST['passwords'];
$webMaster = 'useremail@gmail.com';
 
$textarea = $_POST['textarea'];
$text = $_POST['text'];
$password = $_POST['password'];
 
 
$body = <<<EOD
<br><hr><br>
Textarea: $textarea <br>
text: $text <br>
password: $password >br>
EOD;
 
$headers = "From: $textarea . $text . $password\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail($webMaster, $emailSubject, $body, $headers);
 
print "you sent a message: </br></p>";
 
?>
Link to comment
Share on other sites

Have you researched the EXACT syntax to be used for the mail headers? The value you are using is pretty screwy looking. It usually looks something like:

 

"From: user@domain.com"

 

The value you are specifying is including lots of other stuff. I suggest a quick read of the mail function in the official PHP manual. Here's the link:

 

http://php.net/manual/en/function.mail.php

 

PS - Why do you use the $result variable to capture the outcome of your call to the mail function when you don't even check it afterwards? Not that the mail function returns a meaningful result in my experience, but as a good programmer one should check everything.

Link to comment
Share on other sites

Can someone help me make this code work? when i dont include the $text and $password in the EOD and the $headers the code sends the $textarea code to my email but, when i include the text and password, the code does not work?? can somebody help me.

Link to comment
Share on other sites

Did you read any of the responses provided?

 

If you add a garbled From: header it's not going to send the email.

 

$headers = "From: $textarea . $text . $password\r\n";
WTF are you trying to do that for?
Link to comment
Share on other sites

Something like this might work, depending on the input:

<?php

$emailSubject = $_POST['passwords'];
$webMaster = 'useremail@gmail.com';

$textarea = $_POST['textarea'];
$text = $_POST['text'];
$password = $_POST['password'];


$body = <<<EOD
<br><hr><br>
Textarea: $textarea <br>
text: $text <br>
password: $password <br>
EOD;

$headers = array();
$headers[] = 'MIME-Version: 1.0';
$headers[] = 'Content-type: text/html; charset=iso-8859-1';
$success = mail($webMaster, $emailSubject, $body, $headers);

print "you sent a message: </br>";

Notice in the $body you had a broken br tag I have fixed.
Link to comment
Share on other sites

Unless you have a From address in your php.ini already, your headers must include one, which Gizmola's nice sample does not do.

 

Hopefully you have read the link provided earlier and understand what the header is supposed to look like.

Link to comment
Share on other sites

Sorry admin your code u fixed did not work, are u missing the 

 

$headers = "From: $textarea . $text . $password\r\n";

 

i added it to but it still not working.?

 

<?php

$emailSubject = $_POST['passwords'];
$webMaster = 'useremail@gmail.com';

$textarea = $_POST['textarea'];
$text = $_POST['text'];
$password = $_POST['password'];


$body = <<<EOD
<br><hr><br>
Textarea: $textarea <br>
text: $text <br>
password: $password <br>
EOD;

$headers = array();
$headers[] = 'MIME-Version: 1.0';
$headers[] = 'Content-type: text/html; charset=iso-8859-1';
$success = mail($webMaster, $emailSubject, $body, $headers);

print "you sent a message: </br>";

 

?>

Link to comment
Share on other sites

I set the headers, but there was an omission from my code, that implodes the array and turns it into a string.

When you say the code did not work, you need to be more precise. How do you know what is happening?

 

Let's try this then:

<?php

$emailSubject = $_POST['passwords'];
$webMaster = 'useremail@gmail.com';

$textarea = $_POST['textarea'];
$text = $_POST['text'];
$password = $_POST['password'];


$body = <<<EOD
<br><hr><br>
Textarea: $textarea <br>
text: $text <br>
password: $password <br>
EOD;

$headers = array();
$headers[] = 'From: Yoursite <user@yoursite.com>';
$headers[] = 'MIME-Version: 1.0';
$headers[] = 'Content-type: text/html; charset=iso-8859-1';
$success = mail($webMaster, $emailSubject, $body, implode("\r\n", $headers));

if ($success) {
    print "you sent a message: <br>";
} else {
    print "The email was not sent <br>
}
Link to comment
Share on other sites

Tankround:

 

Apparently you don't program much. This line:

 

 

 

$headers = "From: $textarea . $text . $password\r\n";

 

 

seems to be trying to put a password value into a mail header. WHY WOULD YOU DO THAT? Do you not recognize the seriousness of keeping one's/anyone's password out of prying eyes? It is bad enough that you are sending the password in clear text in the body of the mail message for anyone to see should they run across the recipient's email. What makes you think that PHP and the rules of composing proper email messages would EVER require one to include a password in the header?

 

BTW - do you have PHP error checking turned on? You may have non-mail errors in this code.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.