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
Related
This question has been asked many times. I have looked at the other ones. I think my problem is different.
The code works without the CC header. However when I put the CC header my Mac Mail application acknowledges the CC and it says "Downloading 2 mails" aka the mail that was sent in the $to and the new mail in the Cc... but the email in the CC never comes.
<?php
$to = "myEmail#gmail.com";
$subject = "Test Email";
$body = "Hi, This is a Test Email";
$headers = "From: Test#MyWebsite.com \r\n";
$headers .= 'Cc: myOtherEmail#gmail.com' . "\r\n";
if ( mail($to, $subject, $body, $headers)) {
echo("Email successfully sent to $to");
} else {
echo("Email sending failed...");
}
?>
Ok guys... I solved it... hopefully this helps somebody......
It only seems to work gmail to gmail. I don't know why. Hopefully someone with more experience can say why. But I tried #yahoo, #hotmail, #myWebsite emails in the $to and $from.
I have a few questions regarding sending email in PHP. I've been on google for the last few days and I'm still having trouble getting this to fully work.
My first question is how do I change the "From" section of my email? I have "To: support#mydomain.com" in my "from" section:
I'd like to have just the proper name of my domain (eg: "testingstuff.com" -> "Testing Stuff"). How could I achieve this?
Once I actually open the email everything in it is fine and correct, including the From email address being "support#mydomain.com".
Also my mail won't send to gmail addresses. It shows up in my mail queue and my logs say it is sent but it never is received on my gmail. Do I have to take extra steps for Google to accept my email? If so what are those? Do other major mail provides require the same steps, or are they different steps?
This is my code so far:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
ini_set("sendmail_from", "support#mydomain.com");
class email {
public static function send($to, $subject, $message) {
$headers = "From: Testing Stuff <support#mydomaincom>\r\n";
$headers .= "Reply-To: support#mydomain.com\r\n";
$headers .= "Content-type: text/html\r\n";
mail($to, $subject, $message, $headers);
}
}
?>
Usage:
require_once("../mail.php");
email::send("support#mydomaincom", "testing email subject", "testing email body");
Am I doing anything wrong in my code?
You need to check if the email is sent properly checking the mail() result, in this way:
$result = mail($to, $subject, $message, $headers);
if(!$result) {
echo "Error";
} else {
echo "Success";
}
this is inside your static function,
Also check your spam folder if the mail function return "success".
Hallo I've got a problem with sending html E-mails with a dyanamic Link via PHP.
That is my PHP Code:
$empfaenger = $_POST['email'];
$test = sha1($_POST['email']);
$betreff = "Test Mail";
$from = "From: Peter <tets#gmail.com>\n";
$from .= "Reply-To: test16#gmail.com\n";
$from .= "Content-Type: text/html\n";
$text = "Please click <p><a href='http://defaultpage/default.php?res=".$test."'>here</a></p>.";
mail($empfaenger, $betreff, $text, $from);
In the mail Log all looks normal like the mail is sended, but I didn't receive one. In PHP error Log also nothing. If I set $test to a specified string it's working as expected, but not with the dyanamic variable $test. I hope that someone can help me becuse I can't get rid of this problem.
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?
I have a simple php email script where I wish to include an image at the bottom. When I add the image tags like below the email just shows <img src="http://domain.com/images/logo.png" /> instead of the actual image. Any ideas why?
<?PHP
$email = $_POST["emailaddress"];
$to = "you#youremail.com";
$subject = "New Email Address for Mailing List";
$headers = "From: $email\n";
$headers .= "Content-type: text/html\r\n";
$message = "A visitor to your site has sent the following email address to be added to your mailing list.\n
Email Address: $email";
$user = "$email";
$usersubject = "Thank You";
$userheaders = "From: info#domain.com\n";
$usermessage =
"
Thank you for joining our mailing list.
We hope to see you very soon!
Address 1
Address 2
<img src=\"http://domain.com/images/logo.png\" />
";
mail($to,$subject,$message,$headers);
mail($user,$usersubject,$usermessage,$userheaders);
$fh = fopen("email.xml", "a");
fwrite($fh, "$email\r\n");
fclose($fh);
?>
You're not passing the Content-Type header with the right message. $headers does contain the right header, but it is sent with a plain text message, whereas $userheaders does not contain the Content-Type header, but the message associated with it does contain some HTML
Replace
$userheaders = "From: info#domain.com\n";
with
$userheaders = "From: info#domain.com\r\n";
$userheaders = "Content-type: text/html\r\n";
and it should work perfectly
This is a word press plugin but if you delete everything BUT the XmailBaby class it should work for you nicely.
That code is a nice piece of work that sends emails very good.
It is just a basic version but it should be enough for you.
Take a look through the code, you might find it interesting.
http://plugins.svn.wordpress.org/xmail-the-right-way/trunk/xmail.php
You need to specify html headers. Rather than do this yourself, you can use a well-established method that supports sending HTML emails, such as PHPMailer:
http://phpmailer.worxware.com/