Sending mail failed in php - php

I am trying to send email using mail function in php:
$subject = 'testing';
$email = 'test#gmail.com';
$message = 'test message';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: The test site" . "\r\n";
if (mail($email, $subject, $message, $headers)) {
$data['msg']="Message send successfully";
}
else {
$data['msg']="Please try again, Message could not be sent!";
}
I Encounter following error:
A PHP Error was encountered
Severity: Warning
Message: mail() [function.mail]: SMTP server response: 501 Syntax error in parameters or arguments
Filename: sendemail.php
Line Number: 40
I might guess that error was due to not setting configuration required for sending email in php. What should I need to do or I have to change in php.ini file but it's not accesible. Any solution please?

$subject = 'testing';
$email = 'test#gmail.com';
$message = 'test message';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: The test site" . "\r\n";
$to=$toEmail;
$subject=$sub;
$from="info#mypropick.com";
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\n";
$headers .= "From: <".$from.">\n";
$headers .= "X-Priority: 1\n";
$message='<div style=" width:700px; margin:0 auto; border:1px solid #e2e2e2; padding:20px;">
<h3>MYPROPICK Services:</h3>'.$msg.'</div>';
$message .= "<br/>Regards <br />MYPROPICK.COM";
if (mail($to, $subject, $message, $headers )) {
$data['msg']="Message send successfully";
}
else {
$data['msg']="Please try again, Message could not be sent!";
}

You forgot a closing apostrophe in the code
$message = 'test message;
should be
$message = 'test message';

a quotes " ' " missed in 3rd line
$message = 'test message' ;
^
try :
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: valid#email.com" . "\r\n";
'From' must be a valid email address

SMTP Error 501 : Syntax error in parameters or arguments (e.g. invalid email address)
The command was correct and recognized, but the parameters (the arguments, e.g. email address) were not valid. For example you try to use invalid email address as sender\#domain.com and as "\" is not allowed in email addresses.
http://info.webtoolhub.com/kb-a15-smtp-status-codes-smtp-error-codes-smtp-reply-codes.aspx

Related

postfix send email subject breaks the FROM

I am using postfix to send an email to the user, but the problem is it breaks the words where it finds the space.
Here is the screenshot:
postfix-send-email
PHP code to send an email:
<?php
$subject = "Status Of mail";
$message = "Test Email using Postfix Apache2";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: 'The Travel Worthy' 'pathik#gmail.com"\r\n";
$send = mail('test#yahoo.com', $subject, $message, $headers);
if($send)
{
return 1;
}
else
{
return 0;
}
?>
Try replacing
$headers .= 'From: 'The Travel Worthy' 'pathik#gmail.com"\r\n";
with
$headers .= "From: The Travel Worthy <pathik#gmail.com>\r\n";

PHP - "sendmail_from" not set in php.ini

Setting xampp to be able to send emails through the localhost. Used this guys instructions http://www.root25.com/2014/04/send-email-using-xampp-from-localhost.html and it was pretty straight forward.
It comes up with an error message:
Warning: mail(): "sendmail_from" not set in php.ini or custom "From:"
header missing in C:\xampp\htdocs\process.php on line 56
PHP CODE
if (!($formerrors)) :
$to = "email#email.com";
$subject = "From $myname -- Contact/Booking Page";
$message = "$myname filled out the form";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'From: Patrick <email#email.com>' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$replyto = "From: $email \r\n".
"Reply-To: secondemail#email.com" . "\r\n";
if (mail($to, $subject, $message, $headers)):
$msg = "Thanks for filling out our form";
else:
$msg = "Problem sending the message";
endif; // mail form data
endif; // check for form errors
Not sure what the problem is here. Any advice?

PHP - Not receiving email from contact form

I am not receiving emails from this contact form, but the message seems to sending okay and it also redirects me to the sent page.
I don't have access to the server only via FTP.
PHP
<?php
$to = 'test#gmail.com';
$subject = $_POST['subject'];
$name = $_POST['name'];
$email = $_POST['email'];
$comment = $_POST['comment'];
$body = <<<EMAIL
<html>
<p><h3>Email Submited From Website.</h3></p>
<p><strong>Name:</strong> $name</p>
<p><strong>Email:</strong> $email</p>
<p><strong>Subject:</strong> $subject</p>
<p><strong>Message:</strong> $comment</p>
</html>
EMAIL;
// 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 .= 'To: test email' . "\r\n";
$headers .= 'From: <website#mt.co.uk>' . "\r\n";
//$headers .= 'Cc: noreply#example.com' . "\r\n";
//$headers .= 'Bcc: noreply#example.com' . "\r\n";
if ($_POST['submit']){
mail($to, $subject, $body, $headers);
header ("Location: message-sent.php");
die();
} else {
header ("Location: message-failed.php");
die();
}
?>
Check if mail is actually being sent:
if (mail($to, $subject, $body, $headers)===false) {
echo "Not sent!";
} else {
echo "Sent!";
}
Change this:
$headers .= 'To: test email' . "\r\n";
$headers .= 'From: <website#mt.co.uk>' . "\r\n";
To this:
$headers .= "To: $to <test email>\r\n";
$headers .= "From: website#mt.co.uk <website#mt.co.uk>\r\n";
Also, you need to sanitize the subject and body of the email so that the email arrives, but this will usually be reflected in the results after email() reports a success, in that case the email will bounce, go to the spambox, or simply be refused.
If your hosting provider doesn't have an email server, you could try to use a free email server and phpMailer. https://github.com/PHPMailer/PHPMailer

Add bold text in mail sender text

Here is the code:
$email_body = "You have received a new message. ".
" Here are the details:\n\n Name: $name \n Email: $email_address \n Message \n $message";
I want to add bold text to: "Name:", "Email:", and "Message"
I have tried using the "< b > name: < /b>" (without space of course), but it doesn´t work. I want the text to be bold when i receive the mail.
// 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";
$email_body = "You have received a new message. ".
" Here are the details:\n\n <strong>Name:</strong> $name \n <strong>Email:</strong> $email_address \n Message \n $message";
// Mail it
mail($to, $subject, $message, $headers);
You need To Set Header Content Type Like This:
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
Here is Example ....
<?php
$to = 'recivermail#email.com';
$subject = 'Your Subject';
$from = 'sender#email.com';
// 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";
// Create email headers
$headers .= 'From: '.$from."\r\n".
'Reply-To: '.$from."\r\n" .
'X-Mailer: PHP/' . phpversion();
// Compose a simple HTML email message
$message = '<html><body>';
$message .= '<h1 style="color:#f40;">Your Title</h1>';
$message .= '<b style="color:#080;font-size:18px;">How Are You?</b>';
$message .= '</body></html>';
// Sending email
if(mail($to, $subject, $message, $headers)){
echo 'Your mail has been sent successfully.';
} else{
echo 'Unable to send email. Please try again.';
}
?>

Why is my PHP script not sending emails when set from header

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?

Categories