I am using this simple php mail function and I would like to add to message another text like "this message is from website".
$email="kontakt#fotografernevesterbro.dk";
$from=$_POST["email"];
$subject=$_POST["subject"];
$message=$_POST["message"] + $sitemessage;
$sitemessage= "this is message from website";
mail ($email, $subject, $message, "From:".$from);
I tried to add another variable and put it into mail function but it doesn't work.
Use . to concatenate (not +) and $sitemessage should be appended to $message after it has been assigned a value.
$email="kontakt#fotografernevesterbro.dk";
$from=$_POST["email"];
$subject=$_POST["subject"];
$sitemessage= "this is message from website";
$message=$_POST["message"] . $sitemessage;
mail ($email, $subject, $message, "From:".$from);
This code will simply do what you want.
$email="kontakt#fotografernevesterbro.dk";
$from=$_POST["email"];
$subject=$_POST["subject"];
$headers = "From: $from ";
$message=$_POST["message"];
$message .= " this is message from website";
mail ($email, $subject, $message, $headers);
Related
The first code without $_Post works, the second one with $_POST doesnt. It is on the server in cpanel. Anything helps :)
I tried various things like changing the code in HTML, placing slashes, also using $_request over $_post.
This works -
$to_email = "example#example.hr";
$subject = "Simple Email Test via PHP";
$body = "Hi,nn This is test email send by PHP Script";
$headers = "From: me#example.hr";
if ( mail($to_email, $subject, $body, $headers)){
echo("Email successfully sent to $to_email...");
} else {
echo("Email sending failed...");
}
$to_email = "example#example.hr";
$subject = "Simple Email Test via PHP";
$body = "Poruka:$_POST[poruka]";
$headers = "From: $_POST[email]\n";
if ( mail($to_email, $subject, $body, $headers)){
echo("Email successfully sent to $to_email...");
} else {
echo("Email sending failed...");
}
</code></pre>
The first code sends the email, while the second one goes into echo ("Email sending failed...")
Heres my little code
$to = 'target#adress.pl';
$adres='author#adress.pl';
define('ADR','author#adress.pl');
$subject='Invoice delivery confirmation for '.$adres;
$message=$adres.' confirmed invoice delivery';
$headers = "From: ".$adres."\r\n" .
"Reply-To: ".$adres."\r\nContent-Type: text/plain; charset=utf-8" ;
if (mail($to, $subject, $message, $headers)) echo ' Confirmation has been sent to '.$to.'<br />';`
When i use variables with or without concatenation then headers in sending message are empty - they are replaced with default admin adress. Offcourse variable $adress itself is not empty as it works properly in $subject and $message variables. But if i replace variables with ADR constant or plain text then they do work. Is it PHP, server settings or something else?
The aim of this script is to send an email, but instead of including your name and email, it would include it on the message because the website already has details of this from the PHP session. Currently the "2Email" works.. it can send a message to the recipient's mail box, and includes the user's input message. But it doesn't follow the template. I.E. It doesn't include the text "Sent via the dashbaord"
<?php
session_start();
if(!isset($_SESSION["USER"])){
header("Location: ../login.php?NotAuth");
}
$to = $_POST['2Email'];
$name = $_SESSION["USER"]["FullName"];
$email = $_SESSION["USER"]["Email"];
$subject = $_POST['regarding'];
$message = $_POST['msg'];
$Cc= $_SESSION["USER"]["Email"];
$headers = "From: $email";
$tracker = "This message was sent via the TrackerSystem dashboard";
$message = "Hi, "."\n".$message. "\n". "Regards, ".$name. "\n".$tracker.
$sent = mail($to, $subject, $message, $headers) ;
if($sent) {
print "Sent successfully! XD ";
} else {
print "The server made a booboo, the email didn't send :'( ";
}
?>
Is it a typo on line 19: "\n".$tracker. ? If so, that's what prevents your tracker being appended to the message.
What's actually happening: the whole expression on lines 19-20 (this one):
$message = "Hi, "."\n".$message. "\n". "Regards, ".$name. "\n".$tracker.
$sent = mail($to, $subject, $message, $headers) ;
is being evaluated from right to left (if it even works, of which I doubt). So (first) mail is sent and result is assigned to $sent and (second) the whole concatenated string is assigned to $message.
To fix it, make "\n".$tracker. "\n".$tracker;.
How can i use the mail by header in php?
This is what i use now:
//define the headers we want passed. Note that they are separated with \r\n
$headers = "From: test#gmail.com\r\nReply-To:test#gmail.com";
//send the email
$to = "test#gmail.com";
$subject = "This is a subject";
$body = "Hi there!";
if (mail($to, $subject, $body,$headers))
{
echo("\nMessages successfully sent!");
} else {
echo("\nMessages delivery failed...");
}
I get this on my gmail when i click on show details:
from test#gmail.com
reply-to testreply#gmail.com
to test#gmail.com
date Sat, May 14, 2011 at 12:06 AM
subject stefanos neofitidis! You commented on your poem:Tree present
mailed-by ip-1-1-1-1.ip.secureserver.net
i do not want to the ip-1-1-1-1.ip.secureserver.net to show up to the users...this is what i am trying to change!
Do you mean the X-Mailer?
$headers = "From: test#gmail.com\r\nReply-To:test#gmail.com\r\nX-Mailer: PHP/" . phpversion();
What you want to do is add a fifth parameter in your mail() function, which needs to use the "-f" sendmail option.
For example:
mail($to, $subject, $body, $headers, "-fsender#domain.com");
Sending a message with that last parameter will change the envelope sender to "sender#domain.com". Most of the time, email providers like gmail won't even show that address if it is set by hand(which is what you want, I'm assuming).
See http://us2.php.net/function.mail for more details.
I have successfully sent mail using PHP's mail() function before, and for my password reset notification e-mail, I copied the syntax I was using elsewhere, but I guess I messed it up, as it's not arriving at its destination. Here is the code I'm using:
$headers = 'To:'.$email."\r\n";
$headers .= 'From: webmaster#aromaclear.co.uk'."\r\n";
$to = $email."\r\n";
$subject = 'AromaClear Password Reset Notification'. "\r\n";
$msg = 'From: AromaClear'."\r\n";
$msg .='Subject: Your New Password'. "\r\n";
$msg .= 'Message: Your new password is '.$newpass."\r\n";
$msg.= 'If you have received this e-mail in error, please ignore it.'. "\r\n";
mail($to, $subject, $msg, $headers);
Any thoughts?
Try looking at your server's mail logs to see why it isn't getting forwarded. Ex., it may be that this server's sendmail wants the -f flag for the From header instead of specifying it in the header text.
mail($to, $subject, $msg, $headers, "-f $from");
Also, you seem to be doing a lot of extra/weird work. This is a lot easier:
$subject = "AromaClear Password Reset Notification";
$headers = "From: webmaster#aromaclear.co.uk";
$msg = "Your new password is $newpass\r\nIf you have received this e-mail in error, please ignore it.\r\n.";
if(mail($email, $subject, $msg, $headers))
{
//handle success
}
else
{
//handle failure
}
Change style to your preference.
have you checked the return value of mail(). If it's not FALSE then it's accepted for delivery and the code is fine, but something is messed up somewhere else.
That looks fine to me, perhaps do
if (mail($to_email,$subject,$message, $headers))
echo 'Success';
else
echo 'Error';
}
That might let you know if it's trying to send at all.
Just don't add "\r\n" everywhere, use it only to separate headers.
In the message you can use only \n, it will work.
And at the end of the subject and receiver there's no need for "\r\n".