0

I Have php code to send mail like this :

    <?php
    $to='[email protected]';
    $subject = 'testing';
    //create a boundary string. It must be unique
    $random_hash = md5(date('r', time()));
    //define the headers we want passed. Note that they are separated with \r\n
    $headers = "From: [email protected]\r\nReply-To: [email protected]";
    //add boundary string and mime type specification
    $headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";
    //define the body of the message.
    ob_start(); //Turn on output buffering
    ?>
    --PHP-mixed-<?php echo $random_hash; ?>
    Content-Type: multipart/alternative; boundary="PHP-alt-<?php echo $random_hash; ?>"
    --PHP-alt-<?php echo $random_hash; ?>
    Content-Type: text/plain; charset="iso-8859-1"
    Content-Transfer-Encoding: 7bit

    --PHP-alt-<?php echo $random_hash; ?>
    Content-Type: text/html; charset="iso-8859-1"
    Content-Transfer-Encoding: 7bit

    <?php
//html content
    include ("http://10.*.*.*/maps/tes.php");
    ?>

    --PHP-alt-<?php echo $random_hash; ?>--

    --PHP-mixed-<?php echo $random_hash; ?>
    #Content-Type: application/html; name="racing_mkios_data_wok_sbt_201403.html"
    Content-Transfer-Encoding: base64
    Content-Disposition: attachment

    --PHP-mixed-<?php echo $random_hash; ?>--

    <?php
    //copy current buffer contents into $message variable and delete current output buffer
    $message = ob_get_clean();
    $mail_sent = @mail( $to, $subject, $message, $headers );
    //if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"
    echo $mail_sent ? "Mail sent" : "Mail failed";
    ?>

it send me html code not the content. what wrong wit my code? I had been googling for One Hour still can't find the answer ............................................................

1
  • make sure sendmail works in your server. if not use SMTP. Commented Nov 24, 2016 at 10:31

1 Answer 1

1

Try changing your headers content type to text/html. Switch this line:

 $headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";

to:

 $headers .= "\r\nContent-Type: text/html; boundary=\"PHP-mixed-".$random_hash."\"";
Sign up to request clarification or add additional context in comments.

1 Comment

The PHP mail function simply needs to have its content type set to text/html for it to be able to send HTML mails. More can be found here: php.net/manual/en/function.mail.php

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.