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?
Related
I'm sending out activation code for user sign ups but both Mail() and Pear Mail are literally visiting the links that are placed in the body when it is sent. I've never seen this before and I'm assuming it's a PHP setting turned on that's need to be disabled.
Below is a sample, if you visit test.php it sends an email, however PHP is also reading the link in the body and visits testme.php. That file then sends an email to me as well. I get 2 emails visiting just test.php. It's impossible to create an activation link right now because I keep being activated before receiving an email.
This took me literally 6 hours to realize what was happening and I'm fed up.
Code as a basic test:
test.php:
<?php
$to = 'xxxxxxx';
$subject = "From Test.php";
$body = "Thank you for registering.\n\n To activate your account, please click on this link:\n\n http://xxxxx.com/testme.php\n\n Thanks\n";
$additionalheaders = "From: <XXXXXXX>\r\n";
$additionalheaders .= "Reply-To: XXXXXXX";
mail($to, $subject, $body, $additionalheaders);
echo "done";
?>
testme.php:
<?php
$to = 'xxxxxxx';
$subject = "From Test Me";
$body = "You shouldn't receive this";
$additionalheaders = "From: <xxxxxxx>\r\n";
$additionalheaders .= "Reply-To: xxxxxxx";
mail($to, $subject, $body, $additionalheaders);
?>
Any ideas what would be causing it? Server is running PHP Version 5.4.45
Well I am using the PHP MAIL function and for some reason every email it sends has a weird;
This is at the end of any email as I said, I am not quite sure why this is happening.
$from = 'From: support#phycraft.co.uk';
$to = $user_email; // Send email to our user
$subject = 'PhyCraft Support Ticket :: Closed :: ' . $t_subject; // Give the email a subject
$message = '
Hello '. $username.'.
Your support ticket '.$t_subject.' has been closed due to being inactive for 48 hours.
If you still need help with the ticket please reopen the ticket by replying to it.
~PhyCraft
';
$headers = 'From:support#phycraft.co.uk' . "\r\n"; // Set from headers
mail($to, $subject, $message, $from); // Send our email
I can't see what in the code woud make that appear to be honest.
Most issues with php's mail() function are problems with the MTA and not with PHP itself. I've never heard of this before making it even more likely it's a MTA issue.
You've not provided any useful information beyond the PHP code. What OS is this on (mail() on MSWindows is very different from everyhere else). Do you control the server? What MTA is configured? Have you tried sending an email from the command line?
The extra stuff at the end looks like HTML - is this byte for byte what's in the email or what you see in your mail client?
BTW it's not a good idea to explicitly put "\r\n" at the end of your headers - but you seem to have forgotten to add them as a parameter. Also, your missing a space between "From:" and the email address.
Can you try it with following $headers ( only \n ).
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-Type: text/plain; charset = \"ISO-8859-1\";\n";
$headers .= "Content-Transfer-Encoding: 8bit\n";
$headers .= "From: support#phycraft.co.uk\n";
$headers .= "\n";
mail($to, $subject, $message, $headers);
and 2. try it without
$headers .= "Content-Transfer-Encoding: 8bit\n";
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 want to make an email forwarder similar to cPanel's, where I have a database of email addresses, and where they should forward to, and I set a catch-all to pipe to my script.
I have completed this script, however, I would like to make the "To:" field in the header show the address it was sent to, rather than who is was being delivered to. For example, the email was sent to user001#mydomain.com, and the script forwards it to me#gmail.com. How can I make PHP send mail to me#gmail.com, but still show user001#mydomain.com in the headers, like cPanel does?
You can use the headers of the mail function:
$to = 'me#gmail.com';
$subject = 'Testing';
$message = 'This is a test';
$headers .= 'To: User001 <user001#mydomain.com>, User002 <user002#mydomain.com>' . "\r\n";
$headers .= 'From: My Email Script <me#gmail.com>' . "\r\n";
mail($to, $subject, $message, $headers);
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".