I have a email program that runs from a cron that was working, and now it doesn't. Well, it still works, but it doesn't send any emails to gmail. I have filters setup in gmail's filters to send all emails from: 'my domain' to my inbox instead of the spam folder, but now they don't even go to the spam folder. It works with yahoo and textfree.us.
Here is the code:
$alerttarget = $usersemail;
$subject = "A bill is OVERDUE!";
$body = "You have an overdue bill, in the amount of $" . $amount . ".";
$from = $userId . date("YmdHis") . $billdetailId . "b#mydomain.com";
sendemail($alerttarget, $body, $from, $subject);
function sendemail($target, $body, $from, $subject)
{
$mail = new PHPMailer();
$email = $target;
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "localhost"; // SMTP server
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
$mail->SetFrom($from, "my domain");
$mail->AddReplyTo($from, "my domain");
$mail->Subject = $subject;
$mail->MsgHTML($body);
$address = $email;
$mail->AddAddress($address, "me");
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
}
I recently bought a new domain, and set the host to point to my ip address. I did this with godaddy's DNS manager. But, I only set the host to point to my ip address; nothing else. It stopped working, however, before I did all of this.
Related
I've been using phpmailer for some time and I've noticed now that all my additional to address entries (additional $mail->addAddress or $mail->addCC or $mail->addBCC) cause the page to return:
Could not instantiate mail function.
The page works fine with only one address. I'm using it on Windows 2012 server. I've found some references to those functions not working on Win32, but they used to work. Any ideas?
require 'autoload.php';
//Create a new PHPMailer instance
$mail = new PHPMailer;
$mail -> CharSet = "UTF-8";
$firstname=$_GET['firstname'];
$lastname=$_GET['lastname'];
$email=$_GET['email'];
$phone=$_GET['phone'];
$mail->setFrom('news#imj.org.il', 'News');
$mail->addReplyTo('news#imj.org.il', 'News');
$mail->addAddress('webmaster#imj.org.il', 'Webmaster');
$mail->addAddress('news#imj.org.il', 'News'); /****This doesn't work****/
$mail->addBCC('news#gmail.com');/****This doesn't work****/
$mail->isHTML(true);
$mail->Subject = "Friends Registration";
$mail->Body = "First Name: ".$firstname . "<br>\r\n ";
$mail->Body .= "Last Name: ".$lastname . "<br>\r\n ";
$mail->Body .= "Email: " . $email . "<br>\r\n ";
$mail->Body .= "Tel: " . $phone . "<br>\r\n ";
$mail->AltBody = $firstname." " .$lastname." " . $email;
if(!$mail->send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent successfully";
}
I see that the problem is with the mail server, which also doesn't send multiple email addresses, so I guess it doesn't have to do with phpMailer. Here is the log when I try to send a multiple address mail:
PHP Warning: mail(): SMTP server response: 550 5.7.64 TenantAttribution; Relay Access Denied [DB5EUR03FT036.eop-EUR03.prod.protection.outlook.com] in E:\site\temp\simplemail.php on line 14
I have a WAMP server database which contains users with their emails and activation codes.
How do I send an email for every new record in the WAMP server database automatically with its activation code? Using PHP.
P.s: I can already send an email from WAMP using PHP mailer but I have to specify the receiver each time.
This is the mail.php script that I use for sending emails using PHP mailer
<?php
require "init.php";
require"PHPMailerAutoload.php";
require 'class.phpmailer.php';
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
$mail->Mailer = "smtp";
$mail->Host = "smtp.gmail.com";
$mail->Port = "587";
$mail->IsHTML(true);
$mail->Username = "******#gmail.com";
$mail->Password = "******";
$mail->From = "*******#gmail.com";
$mail->FromName = "Vodafone-El7a2ny";
$mail->AddAddress("*****", "Marwa Hashem");
$mail->Subject = "Activation Code";
$mail->Body = " Dear User,
Thank you for registering in El72any Mobile Application,
Your Activation Code is
Best Regards,
****";
$mail->WordWrap = 50;
if(!$mail->Send()) {
echo 'Email was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
exit;
} else {
echo 'Email has been sent.';
}
?>
This is the register.php script
<?php
require "init.php";
$EmailAddress=$_POST["EmailAddress"];
$MobileNumber=$_POST["MobileNumber"];
$Password=$_POST["Password"];
$sql_query = "insert into user_information VALUES('$EmailAddress', '$MobileNumber', '$Password','');";
if(mysqli_query($con,$sql_query))
{
echo "<h3>Database Insertion Success...</h3>";
}
else
{
echo "Data Inerstion Error...".mysqli_error($con);
}
?>
Also this is the init.php script I used to connect to my database
<?php
$db_name="CustomerDB";
$mysql_user="root";
$mysql_pass=null;
$server_name="localhost";
$con=mysqli_connect($server_name,$mysql_user,$mysql_pass,$db_name);
if(!$con)
{
echo "Connection Error...".mysqli_connect_error();
}
else
{
echo "<h3>Database connection Success...</h3>";
}
?>
This is really an opinion question since you've not posted any code. It helps to start by reading the docs and examples that are provided with PHPMailer. In your case, start with the mailing list example.
I own my domain .com and it is hosted in different provider of the domain.
And I want to use PhpMailer, but my webhosting doesn't provide me SMTP server but it allows me to create emails of my domain (e.g. sdfsdfsfd#mydomain.com)
So, I really can't use phpmailer because it never connects to SMTP server, what should I do?
I brought my domain in onlydomains and my webhost is 000webhost.
<?php
require './PHPMailer-master/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = ''; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'noreply#mydomain.com'; // SMTP username
$mail->Password = '********'; // SMTP password
$mail->SMTPSecure = 'tls';
$mail->From = 'noreply#mydomain.com';
$mail->FromName = 'Admin';
$mail->addAddress('sdfsdf#hotmail.com'); // Name is optional
mail->WordWrap = 50; // Set word wrap to 50 characters
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'swag';
$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';
}
?>
Initially download the php mailer files to your sever(if not downloaded before) & define as following.Avoid using net sources in your code.Once you apply this it will work fine and the mail would be sent as from your mail id.
require("phpmailer/class.phpmailer.php");
$mail = new PHPMailer();
$mail->SMTPDebug = true;
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPAuth = true; // SMTP authentication
$mail->Host = "ssl://smtp.gmail.com"; // SMTP server
$mail->Port = 465; // SMTP Port
$mail->Username = "your mail id"; // SMTP account username
$mail->Password = "password"; // SMTP account password
//The following code allows you to send mail automatically once the code is run
$mail->SetFrom('to mail id', 'name'); // FROM
$mail->AddReplyTo('mail id', 'name'); // Reply TO
$mail->AddAddress('recipient id'); // recipient email
$mail->Subject = "First SMTP Message"; // email subject
$mail->Body = "Hi! \n\n some text.";
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}
After doing the above code if you still not able to send mail means do the following:
In class.smtp.php file add the below given two lines before the line "Connect to the SMTP server" & it ll work fine.
$host = "ssl://smtp.gmail.com";
$port = 465;
I got a Award Space Mail Hosting account.I created that account only for the free email sending feature.
Tried
PHP mailer
swiftmailer ect..
But no use.Can anyone give me a full working code of php and mail form,so that i can just test it in my server .I cound send emails when using this file :
http://www.html-form-guide.com/php-form/php-form-validation.html
But,i dont want that peace of code.I want a perfect code that can work on My server.
Sample code:(Has an html form submit form)
<?php
if(isset($_POST['submit'])) {
$myemail = “support#domain.dx.am”;
$subject = $_POST['subject'];
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$headers = “From:Contact Form <$myemail>\r\n”;
$headers .= “Reply-To: $name <$email>\r\n”;
echo “Your message has been sent successfully!”;
mail($myemail, $subject, $message, $headers);
} else {
echo “An error occurred during the submission of your message”;
}
?>
Or i tried doing the same with php mailer:
<?php
require 'filefolder/mailer/class.phpmailer.php';
$mail = new PHPMailer;
$mail->IsSMTP(); // Set mailer to use SMTP
$mail->Host = 'localhost'; // Specify main and backup server
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'support#whatever.dx.am'; // SMTP username
$mail->Password = 'mypassword'; // SMTP password
$mail->From = 'support#whatever.dx.am';
$mail->FromName = 'Support';
$mail->AddAddress('anything#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';
?>
I am doing something wrong. But cant figure out what. Can anyone help me out .
The 'from' header should be an existing email account inside your Email Manager of your Hosting Control Panel.
as their FAQ says:
Tip: Please note that the 'From' header should be an existing email account inside your Email Manager of your Hosting Control Panel.
FAQ
I am trying to send an email in following way -
from : xyz#domain1.com
reply-to : xyz#domain1.com
to : abc#domain2.com
cc : abc#domain3.com
My email is getting delivered to the address mentioned in CC (If I replace the emails to and cc, then email is sent to the address mentioned in to)
For some reason, email is not getting delivered to the address abc#domain2.com. If I send the email manually to this address using outlook or gmail, then email is actually delivered. How can I debug this issue ?
I checked spam/junk directories as well, no emails over there. I tried using php mail() function as well as phpmailer class. Both of them return TRUE. What could the reason ? Please help.
$mail->From = "xyz#domain1.com";
$mail->AddReplyTo("xyz#domain1.com");
$mail->AddAddress("abc#domain2.com");
$mail->AddCC("abc#domain3.com");
$mail->Subject = $subject;
$mail->Body = $message;
if(! $mail->Send()) {
echo "Message was not sent";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
Try to set cofigurations beffore send (Gmail config):
$mail = new Mailer();
$mail->SMTPDebug = true;
$mail->SMTPAuth = true;
$mail->CharSet = 'utf-8';
$mail->SMTPSecure = 'ssl';
$mail->Host = 'smtp.gmail.com';
$mail->Port = '465';
$mail->Username = 'your login here';
$mail->Password = 'your password here';
$mail->Mailer = 'smtp';
$mail->From = 'form mail address';
$mail->FromName = 'from name';
$mail->Sender = 'form mail';
$mail->Priority = 3;
$mail->AddAddress('mail', 'admin name');
$mail->AddReplyTo('replay to', 'admin name');
$mail->Subject = 'subject';
$mail->Body = 'some HTML message here';
$mail->IsHTML(true);
if(!$this->Send()) {
print_r('error: '. $mail->ErrorInfo); // Show errors
}
$mail->ClearAddresses();
$mail->ClearAttachments();
This can also happen if you are sending email from one email address, but authenticating it against a different one (or domain)
Set $mail.setFrom() to the same email for which you are
authenticating against.
check that your server is aloud to send emails the same happened to me in my case i used plesk and for some reason I was not able to send and email until I receive and email I change this configuration and worked check also is you use send mail o qmail if is qmail you have to tell php mailer