jarv Posted July 20, 2010 Share Posted July 20, 2010 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 More sharing options...
timvdalen Posted July 20, 2010 Share Posted July 20, 2010 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; Link to comment https://forums.phpfreaks.com/topic/208267-help-with-send-mail-code/#findComment-1088474 Share on other sites More sharing options...
jarv Posted July 20, 2010 Author Share Posted July 20, 2010 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 Link to comment https://forums.phpfreaks.com/topic/208267-help-with-send-mail-code/#findComment-1088482 Share on other sites More sharing options...
jarv Posted July 20, 2010 Author Share Posted July 20, 2010 please help? Link to comment https://forums.phpfreaks.com/topic/208267-help-with-send-mail-code/#findComment-1088497 Share on other sites More sharing options...
jarv Posted July 20, 2010 Author Share Posted July 20, 2010 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 Link to comment https://forums.phpfreaks.com/topic/208267-help-with-send-mail-code/#findComment-1088505 Share on other sites More sharing options...
timvdalen Posted July 21, 2010 Share Posted July 21, 2010 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; Link to comment https://forums.phpfreaks.com/topic/208267-help-with-send-mail-code/#findComment-1088951 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.