Here is the code for the PHPMailer and ImprovMX - phpmailer

Below is the code for the PHPMailer and ImprovMX. I have tried to use this code below so I can connect to ImprovMX and us a mail forward. The mx record was updated successfully but still it don't send via mail forward. I am using infinityfree hosting and they said this is not an issuse as you can use PHPMailer because they don't allow mail forwarding on free hosting.enter code here
<?php
$result = "";
if(isset($_POST['send'])){
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->isSMTP();
//$mail->Host = 'smtp.yandex.com';
//$mail->Port = 465;
//$mail->SMTPAuth = true;
//$mail->SMTPSecure = 'ssl';
//$mail->SMTPDebug = 3;
//personal info
$fullname = $_POST['fullname'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$subject = $_POST['subject'];
$body = $_POST['message'];
//end of input info
$mail->setFrom('info#domain.cf');
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = $email . "<br>" . $phone . "<br>" .
$body;
if(!$mail->send()){
$result = 'Message not sent. Please try again';
}else{
$result = 'Message sent. We will respond to you as soon as possible';
}
header("Location:index.php");
}
?>

Related

Wamp Server and PHP mailer

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.

Error with PHPMailer SMTP connect() failed

I'm using PHPMailer from https://github.com/PHPMailer/PHPMailer and using code below:
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com';
$mail->port = '25';
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'xxx#gmail.com'; // SMTP username
$mail->Password = 'xxx'; // SMTP password
$mail->From = 'xxx#gmail.com';
$mail->FromName = 'xxx';
$mail->addAddress('xxx#xxx.com', 'xxx'); // Add a recipient
$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;
} else {
echo 'Message has been sent';
}
When I run this, it gives an error:
Message could not be sent.Mailer Error: SMTP connect() failed.
but when I run it on localhost (windows and xampp) it's successful!

Awardspace Email Setting

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

phpmailer not sending mail to gmail

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.

PHPMailer sometimes send mails sometimes not. I use gmail smtp

I use PHPMailer class to send letter and I use gmail account as smtp server.
problem is what sometimes it work well and visitors get letters, but sometimes no and show me error "Message body is empty" or like that.
I think if be problem in code, so don't sent any letter for websites visitors.
why happien like this? what can be problem?
Change these lines:
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
$mail->Port = 465;
With:
$mail->SMTPSecure = 'tls'; // secure transfer enabled REQUIRED for Gmail
$mail->Port = 587;
and hopefully all will be okay from now on.
my code is
function mail_send($type, $id, $mailadd, $maillname) {
global $lang;
global $site_adress;
global $pavadinimas;
global $tekstas;
global $ivadas;
global $full_date;
global $short_date;
require_once ('includes/phpmailer/class.phpmailer.php');
$mail = new PHPMailer();
$siteuser_name = SQL_ROW("users", "WHERE user_id='1'", "user_name");
$siteadminemail = SQL_ROW("users", "WHERE user_id='1'", "user_email");
$alttext = users_langs(altmailtext);
if ($type == "mailactiveletter") {
$subj = users_langs("mailactivesubject");
$linktur = "$site_adress/$lang/usermail_$type-$id.html#kat";
// var_dump($linktur,$type, $siteuser_name,$siteadminemail);
}
if ($type == "mailchangeadress") {
$subj = users_langs("prisijduomenupriminimas");
$linktur = "$site_adress/$lang/usermail_$type-$id.html#kat";
}
$body = file_get_contents("$linktur");
$body = eregi_replace("[\]", '', $body);
define('GUSER', 'uxxxx#gmail.com'); // Gmail username
define('GPWD', 'xxx'); // Gmail password
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 0; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->Username = GUSER;
$mail->Password = GPWD;
$mail->CharSet = 'UTF-8';
//$mail->AddReplyTo("$siteadminemail", "$siteuser_name");
$mail->AddReplyTo("no-replay#xxx.co.uk", "$siteuser_name");
$mail->AddAddress("$mailadd", "$maillname");
// $mail->SetFrom("$siteadminemail", "$siteuser_name");
$mail->SetFrom("no-replay#xxx.co.uk", "$siteuser_name");
// $mail->AddReplyTo("$mailadd", "$maillname");
$mail->AddReplyTo("no-replay#xxx.co.uk", "$siteuser_name");
$mail->Subject = "$subj";
$mail->AltBody = "$alttext $linktur";
// optional, comment out and test
$mail->MsgHTML($body);
if (!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "";
}
}
Add a $mail->Sender property.
For exemple:
$mail->Sender is the same value of a $mail->From and I add the two lines.
$mail->From = "noreply#test.com";
$mail->Sender = "noreply#test.com";

Resources