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.
Related
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.
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
:)
I'm trying to do a very simple mail form in PHP but get the error:
PHP Notice: Undefined index: in /var/www/html/sites/send_contact.php on line 10, referer: http://example.com/contact2.php
My PHP file looks like this:
<?php // send_contact.php
// Contact subject
$subject =$_POST["$subject"];
// Details
$message=$_POST["$detail"];
// Mail of sender
$mail_from=$_POST["$customer_mail"];
// From
$name2=$_POST["$name2"];
$header="From: $mail_from\r\n";
// Enter your email address
$to="joe#mail.com";
$send_contact=mail($to,$subject,$message,$header);
// Check, if message sent to your email
// display message "We've recived your information"
if($send_contact){
echo "We've recived your contact information";
}
else {
echo "ERROR";
}
?>
The easiest guess is that you're doing a mistake accessing your variables.
instead of:
$name2=$_POST["$name2"];
use this:
$name2=$_POST["name2"];
Or, if you know the difference and are doing this on purpose, make sure your $name2 variable is defined with the correct name of the HTML form field.
As an aside, I would strongly recommend using a library like PHPMailer to send emails.
Your example is quite simple and the mail() should work just fine, but for anything more elaborate (ie. having attachments or html) or needing to send using an external mail server by SMTP (with or without authentication), it will do a much better job and save you lots of time.
For a better idea, check this example from their website:
require_once('../class.phpmailer.php');
$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->Host = "mail.yourdomain.com"; // SMTP server
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Host = "mail.yourdomain.com"; // sets the SMTP server
$mail->Port = 26; // set the SMTP port for the GMAIL server
$mail->Username = "yourname#yourdomain"; // SMTP account username
$mail->Password = "yourpassword"; // SMTP account password
$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></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!
}
The error is telling you exactly what is wrong:
Line 10:
$name2=$_POST["$name2"];
You are using '$name2' before it is defined.
PHP can substitute variables in strings:
$var1 = "bar";
echo "foo $var1"; // prints "foo bar"
In your HTML use something similar to the following:
<input type="...whatever..." name="name2" />
Then in PHP, assuming the data was POSTed, you would access it using:
$name2 = $_POST["name2"];
It seems that your code doesn't pass the $_POST data as you expect. I recommend you to check the keys of $_POST as follows:
<?php
print_r(array_keys($_POST));
?>
If it doesn't display the value of $name2, it means you should modify the web page sending form data to send_contact.php.