dezkit Posted August 27, 2007 Share Posted August 27, 2007 How do i do so i can put php in email scripts? for example <?php $to = "[email protected]"; $subject = "hi sir"; $body = "This person likes you, his name is <?php echo $_POST["name"]; ?>"; if (mail($to, $subject, $body)) { echo("<p>Message successfully sent!</p>"); } else { echo("<p>Message delivery failed...</p>"); } ?> what is wrong with that? why can't i send an email using php? thanks to anyone who responds. Link to comment https://forums.phpfreaks.com/topic/66934-need-help/ Share on other sites More sharing options...
LiamProductions Posted August 27, 2007 Share Posted August 27, 2007 This should work: <?php $to = "[email protected]"; $subject = "Subject"; $message = "Message to email"; if(mail($to, $subject, $message)) { echo "Message sent"; } else { echo "Message failed"; } ?> Is there any errors with that? and do you have STMP {Simple transfer mail protocol} set up Link to comment https://forums.phpfreaks.com/topic/66934-need-help/#findComment-335577 Share on other sites More sharing options...
Dragen Posted August 27, 2007 Share Posted August 27, 2007 you shouldn't use the <?php text inside a variable definition.. <?php $to = "[email protected]"; $subject = "hi sir"; $body = "This person likes you, his name is " . $_POST["name"]; if (mail($to, $subject, $body)) { echo "<p>Message successfully sent!</p>"; } else { echo "<p>Message delivery failed...</p>"; } ?> Link to comment https://forums.phpfreaks.com/topic/66934-need-help/#findComment-335595 Share on other sites More sharing options...
dezkit Posted August 27, 2007 Author Share Posted August 27, 2007 THANK YOU VERY MUCH DRAGEN. I LOVE YOU! Link to comment https://forums.phpfreaks.com/topic/66934-need-help/#findComment-335597 Share on other sites More sharing options...
Dragen Posted August 27, 2007 Share Posted August 27, 2007 hehe. glad I could help Link to comment https://forums.phpfreaks.com/topic/66934-need-help/#findComment-335600 Share on other sites More sharing options...
dezkit Posted August 27, 2007 Author Share Posted August 27, 2007 Wait one second lol <?php $to = "[email protected]"; $subject = "hi sir"; $body = "This person likes you, his name is " . $_POST["name"]; if (mail($to, $subject, $body)) { echo "<p>Message successfully sent!</p>"; } else { echo "<p>Message delivery failed...</p>"; } ?> How do i make multiples? For example : Username: (php code)<br> Password: (php code)<br> etc Link to comment https://forums.phpfreaks.com/topic/66934-need-help/#findComment-335610 Share on other sites More sharing options...
Dragen Posted August 27, 2007 Share Posted August 27, 2007 like this? <?php $to = "[email protected]"; $subject = "hi sir"; $body = "This person likes you, his name is " . $_POST["name"] . "<br />"; $body .= "username: " . $VARIABLE_FOR_USERNAME . "<br />password: " . $VARIABLE_FOR_PASSWORD; // note: the .= above means that it is added to the end of the $body variable, instead of writing over it. if (mail($to, $subject, $body)) { echo "<p>Message successfully sent!</p>"; } else { echo "<p>Message delivery failed...</p>"; } ?> Link to comment https://forums.phpfreaks.com/topic/66934-need-help/#findComment-335617 Share on other sites More sharing options...
dezkit Posted August 27, 2007 Author Share Posted August 27, 2007 damnit >< it doesnt work. This is what comes up in my email: This person likes you, his name is <br />username: <br />password: Link to comment https://forums.phpfreaks.com/topic/66934-need-help/#findComment-335638 Share on other sites More sharing options...
dezkit Posted August 27, 2007 Author Share Posted August 27, 2007 nevermind i coded myself. thanks again haha. and another problem... lol i cant use <br /> <?php $to = "[email protected]"; $subject = "hi sir"; $body = "Username: " . $_POST["username"] . "<br />Password: " . $_POST["password"]; if (mail($to, $subject, $body)) { echo "<p>Message successfully sent!</p>"; } else { echo "<p>Message delivery failed...</p>"; } ?> Link to comment https://forums.phpfreaks.com/topic/66934-need-help/#findComment-335647 Share on other sites More sharing options...
Dragen Posted August 27, 2007 Share Posted August 27, 2007 This should enable hte use of html <?php $headers = "MIME-Version: 1.0\r\n" . "Content-Type: text/html;\r\n"; $to = "[email protected]"; $subject = "hi sir"; $body = "Username: " . $_POST["username"] . "<br />Password: " . $_POST["password"]; if (mail($to, $subject, $body, $headers)) { echo "<p>Message successfully sent!</p>"; } else { echo "<p>Message delivery failed...</p>"; } ?> Link to comment https://forums.phpfreaks.com/topic/66934-need-help/#findComment-335675 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.