I am using corephp and i have used hostgator webmail to send email. Email is successfully going to some testing email provider like mailinator but it is not going to gmail,outlook and company email id.It is not in spam/junk as well. There is no error message recorded and it does not create any exception while sending email.
I am not getting what could be the reason?
This is my actual code.
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isMail(); // Set mailer to use SMTP
$mail->Host = 'http://********/webmail'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'username'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
$mail->From = 'from#example.co';
$mail->FromName = 'Mailer';
$mail->addAddress('To#mailinator.com', 'ToUser'); // Add a recipient
$mail->addAddress('To#mailinator.com'); // Name is optional
$mail->addReplyTo('To#mailinator.com', 'Information');
$mail->addCC('cc#example.com');
$mail->addBCC('bcc#example.com');
$mail->WordWrap = 50; // Set word wrap to 50 characters
$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
Remove This Line from your coding
$mail->addAddress('To#mailinator.com');
You Can Test With Gmail Account you will get mail on your junk mail box. you can report that mail as not a junk mail then you will get mails on outlook.
E.g:
$mail->addAddress('Toemailname#gmail.com', 'ToUser');
Related
This question already has answers here:
How do you make sure email you send programmatically is not automatically marked as spam?
(24 answers)
Closed 6 years ago.
Is there a way I can set the email address used by php's mail() function without getting caught by spam filters?
If I don't add a from header the email is sent from apache#ip-17....3.us-west-2.co....rnal which isn't the worst name because most mail services just shorten to Apache. But I would like to have that be noreply.mydomain.com If I add a from header and put anything else it seems to always get caught by spam but not if just left to default.
My setup is PHP 7 on linux Amazon EC2 Micro
You could also use PHPMailer class at https://github.com/PHPMailer/PHPMailer .
It allows you to use the mail function or use an smtp server transparently . It also handles HTML based emails and attachments so you don't have to write your own implementation.
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'user#example.com'; // SMTP username
$mail->Password = 'secret'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
$mail->From = 'from#example.com';
$mail->FromName = 'Mailer';
$mail->addAddress('joe#example.net', 'Joe User'); // Add a recipient
$mail->addAddress('ellen#example.com'); // Name is optional
$mail->addReplyTo('info#example.com', 'Information');
$mail->addCC('cc#example.com');
$mail->addBCC('bcc#example.com');
$mail->WordWrap = 50; // Set word wrap to 50 characters
$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
I'm close to finishing my first real website, this website uses php mail function to send mail from my website. My script works because I'm running mercury which routes the mail through gmail smtp. Now my question is if someone can tell me how to connect to this smtp server from php because my webhost doesn't allow me acces to the php.ini file.
Thanks in advance
This PHP class will do it for you. Most real webapps don't rely on PHP's mail(), they use this class instead (or swiftmailer, but his one's much easier).
PHPMailer
Sample code (from the linked page)
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'user#example.com'; // SMTP username
$mail->Password = 'secret'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->From = 'from#example.com';
$mail->FromName = 'Mailer';
$mail->addAddress('joe#example.net', 'Joe User'); // Add a recipient
$mail->addAddress('ellen#example.com'); // Name is optional
$mail->addReplyTo('info#example.com', 'Information');
$mail->addCC('cc#example.com');
$mail->addBCC('bcc#example.com');
$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
My code is this.
<html>
<head>
<title>Sending email using PHP</title>
</head>
<body>
<?php
$to = "myemail#gmail.com";
$subject = "This is subject";
$message = "This is simple text message.";
mail($to,$subject,$message);
echo "<br>Message sent successfully...";
?>
</body>
</html>
I know this is very simple but I am not able to solve it my try to help me
Is there a mailserver running on the machine that hosts this page? Most likely not because the code you show should work.
Now there are two options: Install a mailserver or use an additional PHP library to overcome this problem. I'm not gonna post a tutorial on how to install a mailserver so just Google it!
For the PHP library part, u could use PHPMailer. This class holds additional settings for sending the mail via specific servers. First download the needed files from GitHub (on the right side, click "Download zip") https://github.com/PHPMailer/PHPMailer . Unzip the package and copy the files to your working directory. The code could be like:
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'user#example.com'; // SMTP username
$mail->Password = 'secret'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->From = 'from#example.com';
$mail->FromName = 'Mailer';
$mail->addAddress('joe#example.net', 'Joe User'); // Add a recipient
$mail->addAddress('ellen#example.com'); // Name is optional
$mail->addReplyTo('info#example.com', 'Information');
$mail->addCC('cc#example.com');
$mail->addBCC('bcc#example.com');
$mail->WordWrap = 50; // Set word wrap to 50 characters
$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
?>
The easiest way to send mail is to use a gmail account or something. The settings can be found literally everywhere. For example: http://phpmailer.worxware.com/?pg=examplebgmail
I have a webapp to send mails and using PHPMailer.
I have generated a contact list which stores the email addresses in database.
Now in my mail function(web page), I do not have any field to enter email address manually, rather I would like to fetch the email id's from table and send mail to all at one click.
Can someone please help me with this, not knowing what to do.
public function actionSendMail(){
$model = YourModelForMails::model()->findall();
foreach($model as $m){
$this->mailfunction($m['emailcolumn']);
}
}
public function mailfunction($email){
sendyourmail to: $email;
}
SoI will not code for you the app but will give really useful hint to make you workout your app.
Use Yii CActiveRecord based Model to fetch User Data (Normally containing Email and Other Details)
Put PHPMailer in vendors Folder and Import using alias path vendor (Hint Yii::import)
Use PHPMailer and Do the Sending. Here I attach PHPMailer's own example
Put Effort to Make them work together. if you cannot, it means you need to put your work aside and go learning!
Code:
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup server
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'jswan'; // SMTP username
$mail->Password = 'secret'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
$mail->From = 'from#example.com';
$mail->FromName = 'Mailer';
$mail->addAddress('josh#example.net', 'Josh Adams'); // Add a recipient
$mail->addAddress('ellen#example.com'); // Name is optional
$mail->addReplyTo('info#example.com', 'Information');
$mail->addCC('cc#example.com');
$mail->addBCC('bcc#example.com');
$mail->WordWrap = 50; // Set word wrap to 50 characters
$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
echo 'Message has been sent';
I'm using this code to try and get PHPmailer to send emails to people who use my website as gmail has blocked me from using php mail() apparently. However, It returns the error Mailer Error: SMTP Error: The following recipients failed: myemail#gmail.com
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'myhost'; // Specify main and backup server
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'site email'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
$mail->From = 'site email';
$mail->addAddress('myemail#gmail.com'); // Name is optional
$mail->WordWrap = 50; // Set word wrap to 50 characters
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
echo 'Message has been sent';
Can someone help me fix this problem?
mail($to, $subject,$message, $headers, "-fSENDEREMAILID");
try to add -f before the sender email id in the mail function and it works i guess