I have 2 websites on hosted but on one web site I can send mail using php script using other web site I cannot mail using the php script. I don't know where I am going wrong. I even replaced php.ini file. Is there any other thing which I left doing or something.
This is my code
$to="abc#gmail.com";
$subject="test mail";
$body="test mail";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers.='From: Domain <def#gmail.com>' . "\r\n";
if(mail($to,$subject,$body,$header))
{
echo "mailed";
}
else
{
echo "not mailed";
}
I even tried directly embedding message into the mail function that also doesn't seems to be working.
This is the code after embedding message
if(mail("abc#gmail.com", "Test subject", "Test Message", "From: def#gmail.com"))
{
echo "mailed";
}
else
{
echo "error:".mysql_error();
}
I tried contacting my hosting providers technical people. Even they could not find the solution.
it's Sample And Works for me:
$to ='Info#sample.com';
$message = '<a>Hellow</a>';
$subject ='Hello world';
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= "From: <sender#email.com>" . "\r\n";
$mail_sent=#mail($to,$subject,$message,$headers);
echo $mail_sent ? "Success" : "Error";
if this code not working , Call to Your server Administrator For check Server...
Related
We have simple php class, that sends messages via php mail
$message = file_get_contents($this->message_file);
$this->message = base64_encode($message);
foreach($this->to as $to){
$code .= '
$to = "'.$to.'";
$headers = "MIME-Version: 1.0" . "\n";
$headers .= "Content-type: text/html; charset=UTF-8" . "\n";
$headers .= "From: '. $this->from .' " . "\n";
$subject = "Test message from ".$_SERVER[\'SERVER_NAME\'];
mail($to, $subject, base64_decode("'.$this->message.'"), $headers);
';
It worked fine until we had to send proper HTML page with CSS, images and other stuff. Gmail just doesn't show it correct (no images, no css). How can I resolve this and format message in the proper way so google mail will display it right?
I didn't set up anything nor changed any setting on Openshift's side, my code is returning a success status but the mail is not being sent. See my code below:
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= "From: Lubcon Cloud Team <no-reply#lubconcloud.com>" . "\r\n";
$headers .= "Reply-To: no-reply#lubconcloud.com"."\r\n";
$body = "Click the link below to reset your password: <br/><br/> <a href='$resetlink'>$resetlink</a>";
if(mail($to, $subject, $body, $headers)) {
$app->status(200);
$app->response()->write(
json_encode(array("data"=> 'Email Sent'))
);
} else {
$app->status(403);
$app->response()->write(
json_encode(array("code"=>"105", "data"=> "Failed to send email"))
);
}
This code works on my localhost but not when uploaded to Openshift, I am using Ubuntu. Any idea how to make this work without any third party plugins? Do I need to set-up anything?
Thanks
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 have a php script that is only sending mail when the user registration.
I put in something along the lines of:
$to ='testmail#gmail.com';
$message = 'Hello';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: Website <admin#example.com>\r\n";
if($results= mail($to, 'User Registration', 'Test', $headers)) {
echo 'success';
} else {
echo 'fail';
}
But the email doesn't send on server. When i put the following line :
$headers .= "From: Website <admin#example.com>\r\n";
Why is this happening?
Have you looked at the answer to smtp configuration for php mail it's very similar a question to yours?
I am trying to dynamically send text messages using a PHP script. PHP code:
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$textbody=<<<_MESSAGE_
Some text
_MESSAGE_;
mail('myphonenumber#SMSgateway','subject',$textbody,$headers);
I did receive a text message, but it is a "photo message" or rather multimedia instead of text and I am unable to open the message. I have tried playing around with the encoding and $textbody="this text"; instead of *MESSAGE*.
a) How can I send a normal text message (not multimedia)?
b) Why can't I open it?
c) Is there a way for people to respond to the texts I send with text? When I sent myself a text from hotmail I was able to reply and I got the answer in my inbox. When I tried to put $header.= 'From: me <me#somedomain.com>' . "\r\n"; the email wouldn't send
(reason: 553 sorry, your mail was
administratively denied. (#5.7.1))
Thanks!
$sendTo = "test#test.com";
$subject = trim($_POST['subj']);
$headers = "From: ".$_POST['name']."<" . trim($_POST["email"]) .">\r\n";
$headers .= "Reply-To: " . trim($_POST["email"]) . "\r\n";
$headers .= "Return-path: " . trim($_POST["email"]);
$headers .= "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=utf-8\r\n";
$message = strip_tags($_POST["messg"]);
if (#mail($sendTo, $subject, $message, $headers))
{ echo "sent successfully"; }
else
{ echo "Error ... Plz try again later" ; }
This code which I'm using to send emails
I worked before on SMS project so if you have any question about how to link with Getaway feel free to contact me