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
Related
I am sending attachments (CSV) which I have been sending for years using mail() but decided to migrate to SMTP for better reliability.
Code 1 (CSV attachment)
$attachment = $this->CSVData; // "Date","Name","Dept" ... \n"2019-03-13","Dave" ...
$encoding = 'base64';
$contentType = 'text/csv';
$filename = $this->createFileName(); //Get FileDate and Name
$recipient = $delivery_email; // xxxxxxx#gmail.com
$subject = $this->emailHeader['subject'] . " CSV Data";
$message = 'Daily Data File';
$mail = new PHPMailer\PHPMailer\PHPMailer(true); // Passing `true` enables exceptions
try {
//Server settings
$mail->SMTPDebug = 0; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = SMTP_HOST; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = SMTP_USER; // SMTP username
$mail->Password = SMTP_PASS; // SMTP password
$mail->SMTPSecure = SMTP_AUTH; // Enable TLS encryption, `ssl` also accepted
$mail->Port = SMTP_PORT; // TCP port to connect to
//Recipients
$mail->setFrom($this->fromEmail, $this->fromEmailName); // Add a FROM
$addresses = explode(',', $recipient);
foreach ($addresses as $address) {
$mail->AddAddress(trim($address)); // Add a recipient(s)
}
if ( !empty($this->emailCC) ) $mail->addCC($this->emailCC); // Add a CC
//13-03-2019: Add the attachment to the email
$mail->AddStringAttachment($attachment, $filename, $encoding, $contentType);
//Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $subject;
$mail->Body = $message;
$mail->AltBody = 'This email is formatted in HTML';
$mail->send();
$this->fo->printStatus('Email successfully sent to: '. $recipient );
return true;
} catch (Exception $e) {
$this->fo->printStatus( basename(__FILE__) .' '. __LINE__ . ': Message could not be sent. Mailer Error: '. $mail->ErrorInfo );
return false;
}
The email gets delivered to me BUT ...
Problems:
When viewing in Gmail browser - I get message: "
Gmail virus scanners are temporarily unavailable – The attached files haven't been scanned for viruses. Download these files at your own risk."
When viewing in Gmail browser - I cant save/download the file? (clicking the download button does nothing)
When clicking attachment to view in browser, I now get error: "Whoops. There was a problem while previewing this document"
I try "Show Original" and it takes 30+ seconds for the email to load which just shows the base64 encoded data
I tried to open in inbox in Outlook and after 5 minutes of the emails not loading I gave up (thinking the emails are not encoded properly or something causing outlook to get stuck)
It looks like it is working (i.e. the file looks legit based on the gmail icon preview) but I cant do anything else with it and I don't know if it is a Gmail issue or File Issue.
Any advice?
Turns out that Gmail was having issues all yesterday afternoon with attachments. It was a Gmail issue - The timing is unbelievable
https://www.theguardian.com/technology/2019/mar/13/googles-gmail-and-drive-suffer-global-outages
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 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
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.