I am using phpmailer to send email from my online website.but when i sending it showing default server address in from address
<?php
require_once 'phpmailer/class.phpmailer.php';
$mail = new PHPMailer(true); //defaults to using php "mail()"; the true param means it will throw exceptions on errors, which we need to catch
try {
$mail->AddAddress('to#domain.com', 'Jo');
$mail->SetFrom('info#mydomain.com', 'Info');
$mail->AddReplyTo('name#yourdomain.com', 'First Last');
$mail->Subject = 'PHPMailer Test Subject via mail(), advanced';
$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
$mail->MsgHTML('Helooo');
$mail->Send();
echo "Message Sent OK<p></p>\n";
} catch (phpmailerException $e) {
echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
echo $e->getMessage(); //Boring error messages from anything else!
}
?>
now it showing like
i want to replace red marked address to info#mydomain.com....how can i do that...this red marked address is default server address i think. i tried to set address using phpmailer from tag, but no change
try this to change from address
<?php
$to = "somebody#example.com";
$subject = "My subject";
$txt = "Hello world!";
$headers = "From: info#domain.com";
mail($to,$subject,$txt,$headers);
?>
It's very common for hosted email services (e.g. gmail) to not let you change the From address, or restrict you to pre-set aliases, not allowing arbitrary addresses.
It also looks like you've based your code on an obsolete example, and you're probably using an old version of PHPMailer, so get the latest version.
Related
I am using PHPMailer to send mail in my Php program. Email is working fine but it showing mailed by address in from area.How can i hide these mailed by in PHPMailer.and also via details from Email from area.
When i use php mail() function like below its removing mailed by details.But how can i do it in PHPMailer
mail('info#example.com', 'Subj', "Message", $headers, '-freturn#yourdomain.com')
Here is php mailer code
<?php
require_once 'phpmailer/class.phpmailer.php';
$mail = new PHPMailer(true); //defaults to using php "mail()"; the true param means it will throw exceptions on errors, which we need to catch
$body = "Heloooo";
try {
$mail->AddReplyTo('name#yourdomain.com', 'First Last');
$mail->AddAddress('to#example.com', 'John Doe');
$mail->SetFrom('info#example.ae', 'Info');
$mail->AddReplyTo('name#yourdomain.com', 'First Last');
$mail->Subject = 'PHPMailer Test Subject via mail(), advanced';
$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
$mail->MsgHTML($body);
$mail->Send();
echo "Message Sent OK<p></p>\n";
} catch (phpmailerException $e) {
echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
echo $e->getMessage(); //Boring error messages from anything else!
}
?>
You can just remove the below two lines.
$mail->SetFrom('info#example.ae', 'Info');
$mail->AddReplyTo('name#yourdomain.com', 'First Last');
Then the mail details will show from as "Root User root#localhost".
But it will show from which server you are sending it.
Even you use the SMTP with phpmailer, you can do the same.
Below is my code. $to_address adrress in that email is a non-existing email. Is there any way to get an error when we send email to a non-existing email.
error_reporting(E_ALL);
include_once("lib/class/class.phpmailer.php");
$mail = new PHPMailer(true); //the true param means it will throw exceptions on errors, which we need to catch
$from_address= "info#gmail.com";
$to_address = "testq#gmail.com";
try {
$mail->AddAddress($to_address, 'Tom');
$mail->SetFrom($from_address, 'Google');
$mail->Subject = 'testing subject';
$mail->Body = 'Testing body content';
$mail->Send();
echo "Message Sent OK\n";
} catch (phpmailerException $e) {
echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
echo $e->getMessage(); //Boring error messages from anything else!
}
Initially I was using mail(). I changed to php mailer only to get Error details.
Thanks,
Sinaj
How should PHPMailer know that it is wrong emailadres? It's just a wrapper that will create a request to the given SMTP server, which will handle it.
If you want to know that something went wrong, your address need to be in the header (the FROM part), so you'll get an error email.
Try it with an emailclient (online, offline, doesn't matter) and try to send a mail to a non-existing address. You won't get an error either.
I am creating a email service which send different image to different person using phpmail.I can send mail and attachment as i require but when it comes to dynamically adding embedded image in body of mail.
I wont be able to achieve success.
<?php
require_once('class.phpmailer.php');
// multiple recipients
$to = $arr['Contact.Email']; // note the comma
$mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch
$mail->IsSMTP(); // telling the class to use SMTP
try{
$mail->SetFrom($arr['Contact.Email'], 'First Last');
$mail->AddAddress($arr['Contact.Email'], 'John Doe');
$mail->Subject = 'PHPMailer Test';
$mail->AddEmbeddedImage($arr['ContactId'].'.png', 'my-attach');
$mail->Body = 'Your <b>HTML</b> with an embedded Image: <img src=cid:my-attach\'> Here is an image!';
$mail->AddAttachment($arr['ContactId'].".png"); // this is a regular attachment (Not inline)
$mail->Send();
echo "Message Sent OK<p></p>\n";
}
catch (phpmailerException $e) {
echo $e->errorMessage(); //Pretty error messages from PHPMailer
}
catch (Exception $e) {
echo $e->getMessage();
}
?>
I can embed one image but when i try to send different image for different user i get an error.I searched everywhere but i did not get any satisfactorily answer.
any help will be appreciated.
You have an error at:
$mail->Body = 'Your <b>HTML</b> with an embedded Image: <img src=cid:my-attach\'> Here is an image!';
You need to skip the \' after attach.
You also need to set the message to html format by adding:
$mail->IsHTML(true);
Read more about embedding images in the docs here: http://phpmailer.worxware.com/?pg=tutorial
I am using PHPMailer to send HTML emails. I first set the HTML body of the email using HTML and PHP variables after first calling ob_start.
Here's my code:
<?php
ob_start();
?>
..... a bunch of VALID HTML
<?
$body = ob_get_contents();
require_once('class.phpmailer.php');
// Send to Me
$mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch
$mail->IsSendmail(); // telling the class to use SendMail transport
try {
$mail->AddReplyTo('info#example.com', 'Company Name');
$mail->AddAddress('me#example.com', 'My Name');
$mail->SetFrom('info#example.com', 'Company Name');
$mail->Subject = "Contact Form Confirmation";
$mail->AltBody = "This is a contact form submitted through the main website.";
$mail->WordWrap = 50; // set word wrap
$mail->Body = $body;
$mail->IsHTML(true); // send as HTML
$mail->Send(); // Try to send email
} catch (phpmailerException $e) {
echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
echo $e->getMessage(); //Boring error messages from anything else!
}
// end try
For some reason, this line:
$mail->Body = $body;
causes the email not to send. If I replace it with:
$mail->Body = "This is a test email.";
the email sends perfectly.
If my HTML contained within $body is just a valid HTML page with CSS in the head, and no Javascript or anything, why won't the email send?
Is there another way to do this? Please help!!
Turns out, for some reason, the emails were not sending if they contained a fax number. Totally strange. I tested my entire markup, and after ONLY removing a 10 digit phone number, the emails finally went through. I'm not a newbie - literally that's the only text I removed and the emails sent fine.
HAS ANYONE SEEN THIS BEFORE??
Can any one hel me?? I am trying to send an email with attachment it sends the email but the email is send in encoded format I think the problem is with headers can any one give me the working code.. there are lots of ready made code available on net i tried all of them but none of them is working
You can use PHPMailer http://code.google.com/a/apache-extras.org/p/phpmailer/
Dowload Link : http://code.google.com/a/apache-extras.org/p/phpmailer/downloads/detail?name=PHPMailer_5.2.1.zip&can=2&q=
$mail = new PHPMailer(true); //defaults to using php "mail()"; the true param means it will throw exceptions on errors, which we need to catch
try {
$mail->AddReplyTo('name#yourdomain.com', 'First Last');
$mail->AddAddress('whoto#otherdomain.com', 'John Doe');
$mail->SetFrom('name#yourdomain.com', 'First Last');
$mail->AddReplyTo('name#yourdomain.com', 'First Last');
$mail->Subject = 'PHPMailer Test Subject via mail(), advanced';
$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
$mail->MsgHTML(file_get_contents('contents.html'));
$mail->AddAttachment('images/phpmailer.gif'); // attachment
$mail->AddAttachment('images/phpmailer_mini.gif'); // attachment
$mail->Send();
echo "Message Sent OK</p>\n";
} catch (phpmailerException $e) {
echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
echo $e->getMessage(); //Boring error messages from anything else!
}
Thanks
:)