Emailing problem.

Hello.
I am having trouble with an emailing script and any help you can offer will be greatly appreciated.
The background: A user completes a form and on ‘Send’ they are taken to a ‘Thank you’ page which also displays
exactly what will be received on the sent email. Everything works well except for the fact that no email has been sent.
I have numbered the sections of the script. If I remove sections 4,6 and 7 an email will be sent but obviously apart from
the ‘From’, ‘To’, ‘uniqid’ and ‘This is a Mime encoded message’ information nothing is sent.
I therefore believe that the problem is with sections 6 and 7.

[php] <?php
// 1 add From: header
$headers = “From: “.$fromaddress.”\r\n”;

// 2 specify MIME version 1.0
$headers .= “MIME-Version: 1.0\r\n”;

// 3 unique boundary
$boundary = uniqid(“news”);

// 4 tell e-mail client this e-mail contains//alternate versions
$headers .= “Content-Type: multipart/alternative” .
“; boundary = $boundary\r\n\r\n”;

// 5 message to people with clients who don’t understand MIME
$headers .= “This is a MIME encoded message.\r\n\r\n”;

// 6 plain text version of message
$headers .= “–$boundary\r\n” .
“Content-Type: text/plain; charset=ISO-8859-1\r\n” .
“Content-Transfer-Encoding: base64\r\n\r\n”;
$headers .= chunk_split(base64_encode($body2));

// 7 HTML version of message
$headers .= “–$boundary\r\n” .
“Content-Type: text/html; charset=ISO-8859-1\r\n” .
“Content-Transfer-Encoding: base64\r\n\r\n”;
$headers .= chunk_split(base64_encode($body));

// 8 send message
mail($email, $subject, “”, $headers);
?>
[/php]

I should tell you that I am new to this.
Thanks

Locally being developed or is this live?

mail() is not exactly reliable to begin with, it may have sent and ended up in your junk folder; the mail server may not be set up; or it just may have crapped out. You are also not checking if the function returned anything. If you wrap that in an if statement, it will at least return true if it thinks it worked.

You are not the first and won’t be the last. That is why a service or mail library is typically suggested for this issue. It has been asked a number of times before if you do a search for mail here.

I need the item I’m putting together to be self contained as it will probably end up as a ready-to-use free download.
Thanks.

Keep it simple use this. Remeber to sanitize and do the verefication

   $telefon=filter_var($_POST['telefon'], FILTER_SANITIZE_STRING);
    $imie=filter_var($_POST['imie'], FILTER_SANITIZE_STRING);
    $nazwisko=filter_var($_POST['nazwisko'], FILTER_SANITIZE_STRING);
    $mail=filter_var($_POST['email'], FILTER_SANITIZE_STRING);
    $message=filter_var($_POST['message'], FILTER_SANITIZE_STRING);
  $formcontent=" From: $imie \n nazwisko: $nazwisko \n telefon: $telefon \n Email: $mail \n Wiadomosc: $message \n  ";

$recipient = "[email protected]";
$mailheader = “From: $mail \r\n”;

mail($recipient, $mailheader, $formcontent ) or die("Error!");

echo "

Thank you

“;
echo"

your message was sent

”;
?>
Sponsor our Newsletter | Privacy Policy | Terms of Service