This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 6 years ago.
I am having a problem sending an email to the following domains:
#yahoo.com,
#hotmail.com, and
#mncgroup.com
using the PHP mail() function. But there's no problem if I send an email to #gmail.com
Is there something wrong with my code?
$to = "$email";
$subject = "[NO-REPLY]Confirmation Account Pengaduan Keluhan I-news Tv";
$header = "From: inewsit#mncgroup.com \r\n";
$header .= "Akun Information MNC Biro";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = "<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<h1>Selamat Akun Anda Sudah Aktif</h1>
<p>Detail Account Username :</p>
<br>Your username : $hasil[username]
<br> Your Full Name : $hasil[nama]
<br> Your Email Address : $hasil[email]
<br> Your Status Akun : $status_akun1
<br> Your Lever authentication : $hasil[level]
<br> Your Register Date : $hasil[tanggal_register]
<br>Login sekarang ke : <a href='http://mncgroup.hol.es'><i>http://mncgroup.hol.es</i></a>
</body>
</html>";
$retval = mail ($to,$subject,$message,$header);
if( $retval == true ) {
?>
<div class="alert alert-success alert-dismissable">
<a class="panel-close close" data-dismiss="alert">x</a>
<center>Silahkan Cek <strong>Email</strong> Anda</center>
</div>
<?php
when i run this code and i try to send email to 3 domain above, the message does not get into the email
First, try this in your code:
echo (mail($to, $subject, $message, $headers)) ? 'Message sent!' : 'Message not sent!';
Because of mail() function returns true or false depending on whether the mail was accepted for delivery. I recommend you check your spam folder at those addresses. I have heard that mail sent from the free servers due to the amount of abuse goes directly to spam.
Try this sample code for checking purpose:
<?php
$to = 'ANY EMAIL#yahoo.com';
$subject = 'ANY SUBJECT';
$message = 'ANY MESSAGE';
$headers = 'From: check#check.com' . "\r\n" .
'Reply-To: no-reply#check#check.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
echo (mail($to, $subject, $message, $headers)) ? 'Message sent!' : 'Message not sent!';
?>
Try replacing all occurrences of \r\n with PHP_EOL. Something like this:
$to = "$email";
$eol = PHP_EOL;
$subject = "[NO-REPLY]Confirmation Account Pengaduan Keluhan I-news Tv";
$header = "From: inewsit#mncgroup.com $eol";
$header .= "Akun Information MNC Biro";
$headers .= "MIME-Version: 1.0$eol";
$headers .= "Content-Type: text/html; charset=ISO-8859-1$eol";
See if that changes anything.
Related
i have a php script
<?php
$to = 'somebody#somedomain.com';
$subject = 'Test mail';
$message = 'mysitedomain.com';
$from = 'support#mysitedomain.com';
$headers = 'From:' . $from;
mail($to,$subject,$message,$headers);
echo 'Mail Sent.';
?>
When i run this code mail not send. If i change message to mysitedomaincom (without dot before com) the mail send succesfull.
Anybody have a solution for this?
This codes that tells the mailer and the recipient that the email contains well formed HTML that it will need to interpret
If you want you can change content of $message, now with this codes you can send HTML content mail.
<?PHP
$to = 'somebody#somedomain.com';
$subject = 'Test mail';
$headers = "From: Support <support#mysitedomain.com>" . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = '<html><body>';
$message .= '<h1>mysitedomain.com</h1>';
$message .= '</body></html>';
mail($to, $subject, $message, $headers);
?>
I would like to send an email to my gmail account using some simple PHP code. The code below works in terms of execution, however the problem is even thought is says "Message Sent" I am not receiving my email in my gmail account. Please advice
ini_set('SMTP',"smtp.gmail.com");
$to ="example#gmail.com"; // this will be replaced with my actual email
$from ="example#gmail.com"; // this will be replaced with senders email
$message = $_GET['Message'];
$subject = "This is a test";
if(mail($to,$subject,$message,$from))
{
echo "Message Sent";
}
else
{
echo "Message Not Sent";
}
Steps to send a simple email
Go to google
Search for "PHP Mail"
Click the first result
Read, read, keep reading, wait, read it over, read on
Enjoy!
But seriously:
(Examples are taken from PHP.net)
Example 1
Sending a simple email
Using mail() to send a simple email:
<?php
// The message
$message = "Line 1\r\nLine 2\r\nLine 3";
// In case any of our lines are larger than 70 characters, we should use wordwrap()
$message = wordwrap($message, 70, "\r\n");
// Send
mail('caffeinated#example.com', 'My Subject', $message);
?>
Example 2
Sending mail with extra headers.
The addition of basic headers, telling the MUA the From and Reply-To addresses:
<?php
$to = 'nobody#example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
Use his line of code:
$to ="example#gmail.com"; // this will be replaced with my actual email
$from ="example#gmail.com"; // this will be replaced with senders email
$headers = "From: ".$from."\r\n";
$headers .= "Reply-To: ".$from."\r\n";
//$headers .= "CC: susan#example.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = $_GET['Message'];
$subject = "This is a test";
mail($to, $subject, $message, $headers);
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 7 years ago.
I am trying to send an email when the 'Send Email' button is pressed, but the following code won't send anything to my email:
<!DOCTYPE html>
<html>
<form action="email.php" method="post">
<input value="Send Email" name="email" type="submit">
</form>
<?php
if (isset($_POST['email'])) {
$msg = 'hello';
mail('example#gmail.com', 'Sample', $msg);
}
?>
</html>
Any idea on how to make it work?
Use the following PHP code to send the email
<?php
$to = 'nobody#example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
Mail function will not work in Local server.You need to config SMTP on your local server. Take a look at this similar post,
php mail setup in xampp
try this
<?php
$to = "someemail.com"
$subject = "This is subject";
$message = "<b>This is message.</b>";
$message .= "<h1>This is headline.</h1>";
$header = "From:abc#somedomain.com \r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-type: text/html\r\n";
$retval = mail ($to,$subject,$message,$header);
if( $retval == true )
{
echo "Message sent successfully...";
}
else
{
echo "Message could not be sent...";
}
?>
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 7 years ago.
I am trying to use php mail() function on my new web server(linux based server) for my website. The issue is, emails are not sending to domain email addresses like some1#domain.com but its working fine for gmail, yahoo. I don't know what is the issue on it?. please give me suggestions or advice how to solve this issue. I want to send emails to domain-based email addresses.
my code is
//$to = $_POST['femail'];
$to = "<toadd#domain.com>";
$message = "
<html>
<head>
<title>".$subject."</title>
</head>
<body>
<p>Registration request from site</p>
<table>
<tr>
<td>Project Requested</td>
<td>".$project."</td>
</tr>
</table>
</body>
</html>";
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// More headers
$headers .= 'From: <info#domain.com>' . "\r\n";
$headers .= 'Cc: <some#domain.com>' . "\r\n";
$headers .= 'X-Mailer: PHP/' .PHP_VERSION. "\r\n";
#mail($to,$subject,$message,$headers);
I have faced the same issue..after a talk with hosting service provider I came to know that either sender or receiver's email id should be of the hosting domain id like if you have a site test.com either sender or receiver should have #test.com so you may do the same or talk to your hosting service provider.
$to = "toadd#domain.com"; //to address
$subject ="Your Subject";
$message = "Your message";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: info#domain.com' . "\r\n"; //from address
if (mail($to, $subject, $message, $headers) )
{
echo "Mail sent successfully";
}
else
{
echo "failed to send mail";
}
I'm running a website loccaly useing WAMP and have installed Test Mail Server Tool to act as a mail server (all it does is saves the messages as .eml files). I've tried opening the messages with Lotus Notes and gmail (web interface) and both do not interpret the HTML, for example instead of having a clickable link they have <a href='localhost'>click here</a> Did I make a mistake with the headers?
Here is the code I am using
$to = 'bepusslai#fakeinbox.com';
$from = 'From: tester1#localhost.com';
$subject = 'this is a test';
$message = '<html><head></head><body>Hello. Please follow this link to activate your account.'
."r\n".'<a href="http://localhost/proc.php?uid=45ab3"><img src="images/ActivateButton.gif" alt="activate button" />
</body></html>';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; utf-8' . "\r\n";
$headers .= 'From: testk1#localhost.com' . "\r\n";
mail($to, $subject, $message, $from, $headers);
By the way, I was stuck not having a mail server since WAMP doesn't come with one and I red on another question someone recommended Test Mail Server Tool. I'm open to using a different one because it doesn't seem popular.
If you refer to the docs and examples in the docs, you will see that the From information is not a separate argument to mail() but is included with the additional-headers information.
bool mail ( string $to , string $subject , string $message [, string
$additional_headers [, string $additional_parameters ]] )
Remove your $from argument from the call to mail().
mail($to, $subject, $message, $headers);
Look at this example , it works for me :
<?
//change this to your email.
$to = "m#maaking.com";
$from = "m2#maaking.com";
$subject = "Hello! This is HTML email";
//begin of HTML message
$message = "<html>
<body bgcolor=\"#DCEEFC\">
<center>
<b>Looool!!! I am reciving HTML email......</b> <br>
<font color=\"red\">Thanks dud!</font> <br>
* test.com
</center>
<br><br>*** Now you Can send HTML Email <br> Regards<br>MOhammed Ahmed - Palestine
</body>
</html>";
//end of message
// To send the HTML mail we need to set the Content-type header.
$headers = "MIME-Version: 1.0rn";
$headers .= "Content-type: text/html; charset=iso-8859-1rn";
$headers .= "From: $from\r\n";
//options to send to cc+bcc
//$headers .= "Cc: [email]maa#p-i-s.cXom[/email]";
//$headers .= "Bcc: [email]email#example.cXom[/email]";
// now lets send the email.
mail($to, $subject, $message, $headers);
echo "Message has been sent....!";
?>