I tried to send an email vie PHP but got nothing. I don't see what I am doing wrong.
// Send an email.
$subject = 'Welcome to mypage';
$message = 'your registration went fine.';
echo $email;
$a=mail($email, $subject, $message );
echo 'Mail sent, a='.$a;
I checked that $email contains my email address and $a = 1 after running the code. Still my mailbox is empty. Why?
You probably don't have Apache configured correctly. That's why the email isn't sending.
Some mail servers require mail headers:
$header = "MIME-Version 1.0\r\n";
$header .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$header .= "From: ".$sendername." <".$fromemail.">\r\n";
$header .= "X-Mailer: PHP/".phpversion();
mail($email, $subject, $message, $header);
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'm attempting to reply to an email from a php applicaiton. I use php imap to retrieve emails from the mail server. I now want to reply to those messages. I have the message_id returned from imap_fetch_overview. How do i use these values to reply to the email? I tried In-Reply-To but when i check the email the message shows up as a new message rather than a reply to a message.
$overview = imap_fetch_overview($inbox,$email_number,0);
$headers = "From: <test#domain.co.uk> \r\n";
$headers .= "In-Reply-To: ".$overview[0]->message_id."\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$subject = "testing";
$message = "test message2";
mail( "test2#domain.co.uk", $subject, $message, $headers );
How do i solve?
I have upgrade my server php version to 5.4.30
When I use mail() with this version it send mails to other mail id like my company's webmail but when i use Gmail/yahoo Email it fails to send Email and gives 500 Internal Server Error
Code :
<?php
$arr = array('myemail#company.com','myemail#gmail.com');
foreach($arr AS $key => $value)
{
$to = $value;
$subject = "Test Mail";
$message = "<p>TEST</p>";
$from = "senderemail#gmail.com";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=UTF-8\r\n";
$headers .= "From: <".$from.">" ;
mail($to, $subject, $message, $headers);
// It send mail to myemail#company.com this id
// but for gmail id it shows error
}
?>
i change some setting from Server side..i add my site ip into server setting for Connectors and it works like charm again and save my head hair..
<?php
ob_start();
$arr = array('myemail#company.com','myemail#gmail.com');
foreach($arr AS $key => $value)
{
$to = $value;
$subject = "Test Mail";
$message = "<p>TEST</p>";
$from = "senderemail#gmail.com";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=UTF-8\r\n";
$headers .= "From: <".$from.">" ;
mail($to, $subject, $message, $headers);
ob_flush();
}
ob_end_flush();
?>
Before this I am sorry for my bad English
The problem is that this code
$headers = "From: $from\r\n";
$headers .= "Content-type: text/html; charset=UTF-8\r\n";
$headers .= "Reply-To: $replyTo\r\n";
$headers .= "Return-Path: $from\r\n";
$message = wordwrap($message, 68);
if(mail($to, $subject, $message, $headers))
return true;
else
return false;
Send mail, for example, when $message = 'asasasasasasas'
and doesn't send when it's more long!
I'm working on my VPS and there are many other project where it works greatly, even if the $message is big.
What am I doing wrong?
PS: mail() return true
PS2: /var/log/maillog says OK:
mail() on [/var/www/.../Controller.php:213]: To: vla*****ss#gmail.com -- Headers: From: info#mydomain.ru Content-Transfer-Encoding: base64 Reply-To: info#mydomain.ru Return-Path: info#mydomain.ru
UPD New testing shows that if i delete adresses like ttt.domain.ru in message mail() sended greatly... i can't understand..
For some reason when I send an email message, the HTML is still being displayed in plain text. Can someone please tell me what I'm doing wrong here?
Here is the code:
$to = $_SESSION['customer_email'];
$from = "noreplay#mysite.com";
$subject = "Confirmation for Appointment on ".$_SESSION['display_date'];
$headers = "From: ".$from."\r\n";
$headers .= "Content-type: text/html; charseet=UTF-8;\r\n";
$headers .= "MIME-Version: 1.0;\r\n";
$message = "<p>Thank you".$_SESSION['firstname']." for booking online. Your appointment has been confirmed and is scheduled for <strong>".$_SESSION['display_date']."</strong> between the hours of <strong>".$_SESSION['display_time']."</strong>.</p><p> Please expect our crew to arrive between your two hour arrival window. You will receive a courtesy call when our crew is <span>15-30 minutes</span> away. A confirmation email has been sent to <strong>".$_SESSION['customer_email']."</strong>. </p><p> If you have any questions or need to make any changes to your appointment, please contact our office at <strong>1-800-333-1111</strong>. Thank you for choosing Us!
</p>";
if(mail($to, $subject, $message, $header ))
{
$msg = "Your message has been sent";
}
$headers .= "Content-type: text/html; charseet=UTF-8;\r\n";
should be
$headers .= "Content-type: text/html; charset=UTF-8;\r\n";
Two typos:
if(mail($to, $subject, $message, $header ))
should be
if(mail($to, $subject, $message, $headers ))
and in
$headers .= "Content-type: text/html; charseet=UTF-8;\r\n";
change your 'charseet' to
Content-Type: text/html; charset=ISO-8859-1\r\n
It appears nowadays you can use UTF-8
Content-Type: text/html; charset=UTF-8\r\n
and
if(mail($to, $subject, $message, $header))
to
if(mail($to, $subject, $message, $headers))
also mail's RETURN:
Returns TRUE if the mail was successfully accepted for delivery, FALSE otherwise.
It is important to note that just because the mail was accepted for delivery, it
does NOT mean the mail will actually reach the intended destination.