Jump to content

help with send mail code


jarv

Recommended Posts

I don't think I have put the php in my send me form right, can someone please help?

 

thanks

 

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

Message from: <?php $_REQUEST['username'] ;?>
<?php $_REQUEST['message'] ;?>

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

Message from: <h2><?php $_REQUEST['username'] ;?></h2>
<p><?php $_REQUEST['message'] ;?></p>

--PHP-alt-<?php echo $random_hash; ?>--
<?
//copy current buffer contents into $message variable and delete current output buffer
$message = ob_get_clean();
//send the email
$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";
?>

Link to comment
https://forums.phpfreaks.com/topic/208267-help-with-send-mail-code/
Share on other sites

What host are you using? Most free hosts don't support mailing from php.

I'm also a little confused about why you would choose to use ob_start() here.

 

Personally, I would use:

$message = <<<ENDMESS

--PHP-alt-$random_hash 
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

Message from:$_REQUEST['username'] 
$_REQUEST['message']

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

Message from: <h2>$_REQUEST['username'] </h2>
<p> $_REQUEST['message']</p>

--PHP-alt- $random_hash--

ENDMESS;

ok, I have changed it to this:

 

<?php

    //change this to your email.
    $to = "[email protected]";
    $from = $HTTP_POST_VARS['email'];
    $subject = "email from iphone.jbiddulph.com";

    //begin of HTML message
    $message = <<<EOF
<html>
  <body bgcolor="#DCEEFC">
        <b>$HTTP_POST_VARS['username'];</b> <br>
      <br><br>$HTTP_POST_VARS['message'];
  </body>
</html>
EOF;
   //end of message
    $headers  = "From: $from\r\n";
    $headers .= "Content-type: text/html\r\n";

    //options to send to cc+bcc
    //$headers .= "Cc: [email][email protected][/email]";
    //$headers .= "Bcc: [email][email protected][/email]";
    
    // now lets send the email.
    mail($to, $subject, $message, $headers);

    echo "Message has been sent....!";

?>

 

Can someone please tell me why I am getting the error: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in D:\jbiddulph.com\wwwroot\iphone\send_email.php  on line 12

the problem lies in this line of code

 

<html><body bgcolor="#DCEEFC"><b>$HTTP_POST_VARS['username'];</b><br><br><br>"."$HTTP_POST_VARS['message'];"."</body></html>

 

error message: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in D:\jbiddulph.com\wwwroot\iphone\send_email.php  on line 10

You can't use array variables like that, I'm sorry I didn't point that out earlier.

Use $var = $HTTP_POST_VARS['username']; or do it like this:

    $message = <<<EOF
<html>
  <body bgcolor="#DCEEFC">
        <b>{$HTTP_POST_VARS['username']}</b> <br>
      <br><br>{$HTTP_POST_VARS['message']}
  </body>
</html>
EOF;

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.