I have a php script that sends an email. It looks like this:
<?php
// subject
$subject = "$first_name $last_name has sent you a message on The Red-line";
// message
$message = "<html>
<head>
<title>
The Red-line
</title>
</head>
<body>
<p>
Hi $war_first,
</p> <br />
<p>
$first_name $last_name has sent you a message on the Red-line. To view your message, please login to <a href='www.thered-line.com'>the Red-line.</a>
</p> <br />
<p>
Sincerely,
</p> <br />
<p>
The Red-line Operator
</p>
</body>
</html>";
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= "From: The Red-line messages#theredline.com \r\n";
$headers .= "To: $war_first $last_war <$war_mail>\r\n";
// Mail it
mail($war_mail, $subject, $message, $headers);
?>
When I was testing this out on the remote server, I used this script to send an email to my inbox at turbocapitalist1987#yahoo.com. I got the email but the "from" part doesn't work . Yahoo says that my email was sent from "the#yahoo.com"
Does anybody have a clue as to why this isn't working?
Thanks
For your From header, enclose the actual address with < >:
$headers .= "From: The Red-line <messages#theredline.com> \r\n";
This is the correct format to use when you have both a display name and an email address. I'm guessing Yahoo was interpreting the first word "The" as the entire email address, and provided a default (yahoo.com) for the domain.
The <> seems to be your problem, it should be:
$headers .= "From: The Red-line <messages#theredline.com> \r\n";
Secondly, on Unix/Linux, you must have a working MTA (i.e.: sendmail, postfix, etc.) configured on your server, either to relay mail directly, or through a Smart Host. If you're on Windows, you must have a SMTP server configured in php.ini.
I would recommend using pre-built PHP email library such as: http://swiftmailer.org/
Related
I'm trying to test if the return-path will bounce back on my gmail, but not.
I'm testing to send it to my email (enalds#gmail.com): it works!
And send to unknown email (gifjgogsdkg#fafasfsa.com): it didn't bounce back.
Here's my code
<?php
$message = '
<html>
<head>
<title>Sample Email</title>
</head>
<body>
Sample Email
<br /><br />
Click here to Unsubscribe
</body>
</html>
';
$sender = "enalds#gmail.com";
$email_address = "sender_name#yahoo.com";
$subject = "Testing Email";
$template_name = "Sample Email";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'Return-Path: enalds#gmail.com' . "\r\n";
$headers .= 'From: '.$sender.'' . "\r\n";
if(mail($email_address, $subject, $message, $headers, '-fenalds#gmail.com'))
echo "{$i}. {$email_address} - <span style='color:green'>Successfully</span> Sent [{$template_name}]<br />";
else
echo "{$i}. {$email_address} - <span style='color:green'>Unsuccessfully</span> Sent [{$template_name}]<br />";
You have two solutions to this issue:
First one is leave blank in the php.ini configuration file the "sendmail_from" variable.
This way you could add the additional parameters in the mail function like you have in your code.
The second approach, is set "sendmail_from" in php.ini if you want to have always the same "Return-Path" for every email.
I have created a website and hosted on a free server from 000webhost. I am sending an activation email for the registered users.
code
$to = "$email1";
$subject = 'Account Activation';
$message = '<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div style="margin-left: 100px">
<h1 >Hello '.$username.'</h1>
<p >• This mail is for your account activation .</p></br>
<p>• Please click on the below link to get your account activated.</p></br>
<p>• Login with your username and password after activation.</p>
</div>
</body>';
$headers = "MIME-Version: 1.0" . "\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\n";
$headers .= 'From: <developer#mysite.com>' . "\n";
mail($to, $subject, $message, $headers);
echo "success";
The problem is that whenever I send mail with from address shown above, the mails are not sent. The problem lies in that one line where i use from address in headers because if use some other names such as 'name#example.com' (here example is some other name) the mails are sent. The problem comes whenever i use mail provided by my hosting server. Can anyone help please?
From PHP: mail() $additional_headers:
Multiple extra headers should be separated with a CRLF (\r\n)
So split headers with \r\n:
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: <developer#mysite.com>' . "\r\n";
Check your $to is working or not.
or check spam folder in the recipient's mail.
Otherwise all thing is ok.
Further clarification go func_mail_mail
Please find the code below. This code resides in mydomainname.com
mail("mymail#gmail.com,mymail#mydomainname.com","Testing mail","This is a test mail.","From: mymail#yahoo.com\n");
and
mail("mymail#gmail.com,mymail#mydomainname.com","Testing mail","This is a test mail.","From: mymail#mydomainname.com\n");
I am getting mail to my gmail account (or any yahoo account) for both code, but I am not receiving mail to my webmail or cPanel squirrelmail etc.
I can directly send email to this domain email account
Will the mail server of this domain prevents mails from same domain?
The code worked earlier for the same domainname.
Is it a problem with hosting side? It's a shared server.
Try this
<?php
$to = "admin#gmail.com,mymail#gmail.com";
$subject = "Following Customer Signed Up";
$message = " $username,Customer is signed up with us,<br /><br />
Thanks <br />";
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
// More headers
$headers .= 'From: <mymail#mydomainname.com>' . "\r\n";
$mail=mail($to,$subject,$message,$headers);
?>
I'm using the php mail function and I have no problem sending the emails, I recieve well the emails on Hotmail and Gmail. But, when I wrote a web address in the message Gmail doesn't accepts the email because it arrives with an hyperlink, even though i'm writing the address in this way: "www.something.com" and I'm using Content-Type: text/plain; on the header.
I've tried to use strip_tags() with the message, but the problem persist.
What can I do?
Please try the code as follow:
<?php
$to = "to_email addrss";
$subject = "Your Subject";
$message = "
<html>
<head>
<title>HTML email</title>
</head>
<body>
<p>This email contains HTML Tags!</p>
<a href='http://yourlink.com'>http://yourlink.com</a>
</body>
</html>
";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: <webmaster#yoursite>' . "\r\n";
mail($to,$subject,$message,$headers);
?>
May be you failed to add content-type:text/html ,while sending your email address. may be this is the reason your anchor link it not working.hope this will work.
I'm not sure what happen to my email code as i'm comparing with all the code i able to find online ... when i using localhost, it's work no problem.. and it having the txt file appear in mailoutput folder in xampp.
but when i request my friend to help host to web service.. it cannot work anymore for the code :(
below is my code. (modified from online source)
$subject = "Thanks for Registering." ;
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From : email' . "\r\n";
$message = "<html><body>
<p> Thank you to register with Lecture Public Room Book Portal </p>
<p> </p>
<p> In order to activate your account please click the link below:</p>
<p> <a href='link'>Verify Account</a> </p>
<p></p>
<p>Or you may go to the verification page using below link and paste in the verification code. Your verification code is $ver_code.</p>
<p> <a href='link'> Verify page </a> </p>
<p> </p>
<p> Please do not reply to this email has the mailbox isn't monitored.</p>
<p> </p>
<p> </p>
<p><center> - The Webmaster () - </center> </p>
</body></html>";
if(mail($email, $subject, $message, $headers))
{
$_SESSION['type'] = "User";
echo ("<SCRIPT LANGUAGE='JavaScript'>
window.alert('Successful register. Please check your email for activate account.')
window.location.href='index.php?user=$username#verify-slide';
</SCRIPT>");
exit();
}
else
{
echo ("<SCRIPT LANGUAGE='JavaScript'>
window.alert('Please try again.')
window.location.href='index.php?signup-slide';
</SCRIPT>");
exit();
}
wish someone could please help me :(
Maybe your hoster restricted access to php mail function. Email him about it. If so you can use Mandrill app.
Please check your error log if it returns some errors.
$headers .= 'From : email' . "\r\n";
Put your email in the email field ( preferably from the same domain email address )
A few bullet points (Assuming that mail() returns true and there are no errors in the error log) :
Does the sender address ("From") belong to a domain on your server? If not, make it so.
Is your server on a blacklist (e.g. check IP on spamhaus.org)? This is a remote possibility with shared hosting.
Are mails filtered by a spam filter? Open an account with a freemailer that has a spam folder and find out. Also, try sending mail to an address without a spam filter.
Do you possibly need the fifth parameter "-f" of mail() to add a sender address? (See mail() command in the PHP manual)
If you have access to log files, check those, of course, as suggested above.
Do you check the "from:" address for possible bounce mails ("Returned to sender")? You can also set up a separate "errors-to" address.
from here
In your current page email recipient is not set like this:
$subject = "Thanks for Registering." ;
$from = "admin#abc.com";
$email = "someone#gmail.com";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From :' . $from. "\r\n";