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?
Related
I am using a PHP script to send e-mails to a list of friends. This used to work successfully but now the only e-mails that are sent successfully are those inside my domain ("mycompany.com"). Any e-mails outside my domain fail to be sent. Is this a problem with permissions? Could I fix it by changing the headers I use when I call the mail() function? Here is the PHP script:
$name = "Joe Smith";
$email = "jsmith#mycompany.com";
$to = "ajones#mycompany.com, tom#abc.com, ted#def.com, mary#ghi.com";
$subject = "Dinner Invitations";
$message = "Invitation to Dinner";
$headers = "From: ".$name."<".$email.">\r\n";
$headers .= "Reply-To: ".$email."\r\n";
$headers .= "Return-Path: ".$email."\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'Content-Transfer-Encoding: quoted-printable' . "\r\n";
mail($to, $subject, $message, $headers);
Only ajones#mycompany.com was sent out by the server. tom#abc.com, ted#def.com, and mary#ghi.com did not get sent.
Any suggestions would be deeply appreciated!
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
my php mail() function is not working even its right here it is
$to = $email_id;
$sub = "FORGOT PASSWORD";
$msg = $password;
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'From: Your name <example#gmail.com>' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$mail= mail($to,$sub,$msg,$headers);
if($mail)
{
?>
<script>alert('Your password has been successfully sent to you');</script>
<?
}
else
{
?>
<script>alert('Please try again later');</script>
<?
}
its alert if part i.e. Your password has been successfully sent to you but i did not received any email please help me and i am not using any HTML css in sending this mail.
your headers are incorrect use your headers in this way it will resolved your problem getting true part is not a big deal
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'From: Your name <example#you_domain_name.com>' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
if not resolved give me the result you get using var_dump($mail); showing bool(true)
use
$mail= mail($to, $sub, $msg, $headers);
You dont need string as all variables are Already string.
Use this mail($to, $sub, $msg, $headers),
If it returns true, then check your spam folder.
Write your domain name
$headers .= 'From: Your name <example#yorudomainname>' . "\r\n";
example <example#stackoverflow.com/>
no need to use "" in the mail function if you are storing it in a variable allready.
second thing check what you are getting in $email_id; variable is it the correct email address you are trying to send email .
simply use like this
<?php
$to = $email_id;
$sub = "FORGOT PASSWORD";
$msg = $password;
$headers = "From: webmaster#example.com" . "\r\n" .
"CC: somebodyelse#example.com";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$mail=mail($to,$sub,$msg ,$headers);
if($mail)
{
?>
<script>alert('Your password has been successfully sent to you');</script>
<?
}
else
{
?>
<script>alert('Please try again later');</script>
<?
}
?>
Update
also please check your spam folder. as if you are using other domain as from email these emails may go to the spam folder . or you can use these headers
$headers = "From: webmaster#example.com" . "\r\n" .
"CC: somebodyelse#yourdimain.com"; // enter your domain email
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
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
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