Jump to content

Recommended Posts

How do i do so i can put php in email scripts? for example

 

<?php
$to = "me@Myself.com";
$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

This should work:

 

<?php

$to = "email@address.com";
$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

you shouldn't use the <?php text inside a variable definition..

<?php
$to = "me@Myself.com";
$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

Wait one second lol

 

<?php
$to = "me@Myself.com";
$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

like this?

<?php
$to = "me@Myself.com";
$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

nevermind i coded myself. thanks again haha.

and another problem... lol

 

i cant use

<br />

 

<?php
$to = "me@msas.com";
$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

This should enable hte use of html

<?php
$headers = "MIME-Version: 1.0\r\n" .
      "Content-Type: text/html;\r\n";

$to = "me@msas.com";
$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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.