how to send email to (-pauline#vista.com.my-) and (-$email-)? - php

<?php
$full_name= $_GET["full_name"];
$email= $_GET["email"];
$telephone= $_GET["telephone"];
$option1= $_GET["option1"];
$option2= $_GET["option2"];
$message= $_GET["message"];
require_once('class.phpmailer.php');
$mail = new PHPMailer(); // defaults to using php "mail()"
$mail->AddReplyTo("pauline#vista.com.my","Vista");
$mail->SetFrom('pauline#vista.com.my', 'Vista');
$mail->AddReplyTo("pauline#vista.com.my","Vista");
$address = "pauline#vista.com.my";
$mail->AddAddress($address, "Vista");
$mail->Subject = "Vista";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->Body = "VISTA Eye Specialist Form <br><br>
Name : $full_name<br>
Email : $email<br>
Contact : $telephone<br>
Branches : $option1<br>
Services : $option2<br>
Comments : $message<br>
Thank You!<br>
";
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Please Wait...!<br>
Name : $full_name<br>
Email : $email<br>
Contact : $telephone<br>
Branches : $option1<br>
Services : $option2<br>
Comments : $message<br>
Thank You!<br>
";
}
?>
<html>
<head>
<script>
<!--
timeout = '4000'; // milliseconds/1000th of a sec
window.onload = setTimeout(myRedirect, timeout); // ensure we load the whole page
function myRedirect() {
window.location = "index.php";
}
//-->
</script>
</head>
<body>
</body>
</html>

If you mean, how can you send an email to (-pauline#vista.com.my-) and some other email you specify - basically, more than one person. Just call the addAddress() method again.
$mail->AddAddress('myotheraddress#address.com', "The Name");

Related

phpmailer doesn't send important information (email address entry)

Someone built this site for me and I have no idea about php and which part I should fix :S
Basically I have this single text entry form on my site which users can enter in their email address to that form and once they send submit I'll get the email address they input in.
The dev used phpmailer and at the moment when someone submitted their email address, I don't get any of their email address. The only entry/ email content I get is from "me" and a content of "Thank you. We'll update you as soon as possible."
This is the sendmail.php on the root folder:
<?php
$from = "ask#michaelfrieda2014.com";
if (isset($_REQUEST['email']) && $_REQUEST['email'] != '')
{
$email = $_REQUEST['email'];
sendMailSingup($from, $email);
sendMailSingup($from, "ask#michaelfrieda2014.com");
}
function sendMailSingup($from, $to)
{
include_once('phpmailer/class.phpmailer.php');
$mail = new PHPMailer();
$body = "Thank you. We'll update you a soon as possible.";
$mail->From = "$from";
$mail->FromName = "";
$mail->Subject = "Thank you!";
$mail->AltBody = "Thank you!"; // optional, comment out and test
$mail->MsgHTML($body);
$mail->AddAddress("$to", "");
//$mail->AddAttachment("images/phpmailer.gif"); // attachment
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
#echo "Message sent!";
echo 1;
}
}
How do I make it so that I get the important information? (Their email address sent to my email). Am I missing something?
Thanks!
Below this line...
$body = "Thank you. We'll update you a soon as possible.";
add:
$body .= "<br><br>Sent from: $to";
(note the .= -- this will append to the $body variable)
If you want to fix the reply-to address, add this line:
$mail->AddReplyTo($to, $to);
before:
$mail->From = "$from";

PHP Mailer Attachments Not Uploading?

I am trying to set up PHP Mailer to allow me to send attachments, mainly just images, from a form. I have the following code working except I am not receiving the attachments, they are not being uploaded. Can anybody help me or point me in the right direction as to what I am missing?
PHP
<?php
require 'class.phpmailer.php';
date_default_timezone_set('Europe/London');
$mail = new PHPMailer;
$current=date('l F dS, Y, H:i a');
$mail->From = 'me#example.com';
$mail->FromName = 'Mailer';
$mail->addAddress('karina#live.co.uk', 'Karina McG');
$mail->addAddress('me#live.com');
$mail->addReplyTo('noreply#tempur.com');
$mail->addCC('');
$mail->addBCC('');
$mail->addAttachment('/var/tmp/file.tar.gz');
$mail->addAttachment('/tmp/image.jpg', 'new.jpg');
$mail->isHTML(true);
$name=$_POST['name'];
$subject=$_POST['subject'];
$system=$_POST['system'];
$country=$_POST['country'];
$description=$_POST['description'];
$mail->Subject = "TEMPUR Web Support Request - $system";
$mail->Body = "Dear $name,<br>
<br>
We have received your TEMPUR request form! - $current<br>
<br>
We will be in contact shortly regarding your issue/s.<br>
<br>
Name : $name <br>
Country : $country <br>
Subject : $subject <br>
System : $system <br>
Description : $description";
$mail->AltBody = 'Hehehe';
//$to="$email";//Will change to Digital Users email!
//Send email
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
echo 'Message has been sent';
?>
HTML
Upload File:<input type="file" name="upload" id="upload"><br>
add enctype="multipart/form-data" to the form as attribute if it is not their.
also try $mail->addAttachment($_FILES["upload"]["tmp_name"]);
It will work.

What's the best way, in this situation, to structure and action/generate two different emails from one form submit button via PHP Mailer?

Educate me :)
I have a simple HTML form consisting of 3 fields: name, email and message.
I have created below some PHP code which will act as an auto-responder to the email address entered into the form containing a fixed message and an attachment.
I wish for a second email to be sent out to a fixed email address to a company which will only contain the name, email and message entered into the form.
<?php
$field_fullname = $_POST['cf_mercury']; // cf_name is a convention used by the HTML form
$field_email = $_POST['cf_jupiter'];
$field_message = $_POST['cf_uranus'];
require_once('class.phpmailer.php');
$mail = new PHPMailer(); // defaults to using php "mail()"
$body = $field_message;
$mail->SetFrom("company#address.co.uk", "ETAP Centre");
$mail->AddReplyTo("company#address.co.uk", "ETAP Centre");
$address = "email#address.co.uk";
$mail->AddAddress($field_email, $field_fullname);
$mail->Subject = 'Auto Response: Message from the ETAP Centre';
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$mail->AddAttachment(""); // attachment
$mail->AddAttachment(""); // attachment
if(!$mail->Send()) {
{ ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send your email to company#address.co.uk');
window.location = 'index.html';
</script>
<?php
}
} else {
?>
<script language="javascript" type="text/javascript">
alert('Thank you for contacting the ETAP Centre. We will contact you shortly.');
window.location = 'index.html';
</script>
<?php
}
?>
Any and all help would be hugely appreciated and if I can do anything more to articulate my question and increase its understandability just let me know. Thank you!
<?php
$field_fullname = $_POST['cf_mercury']; // cf_name is a convention used by the HTML form
$field_email = $_POST['cf_jupiter'];
$field_message = $_POST['cf_uranus'];
require_once('class.phpmailer.php');
$mail = new PHPMailer(); // defaults to using php "mail()"
$body = "Message";
$mail->SetFrom('company#address.co.uk', 'ETAP Centre');
$mail->AddReplyTo('company#address.co.uk', 'ETAP Centre');
$address = $field_email;
$mail->AddAddress($address, $field_fullname);
$mail->Subject = 'Auto-Response: Thank you for contacting the ETAP Centre, '.$field_fullname;
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$mail->AddAttachment("/websites/123reg/LinuxPackage22/da/mt/ec/damtechdesigns.co.uk/public_html/proofs/etap/etapbooklet.pdf"); // attachment
$mail->AddAttachment(""); // attachment
$mail->Send();
// E-Mail to Company
$mail = new PHPMailer(); // defaults to using php "mail()"
$body = $field_message;
$mail->SetFrom($field_email, $field_fullname);
$mail->AddReplyTo($field_email,$field_fullname);
$address = "company#address.co.uk";
$mail->AddAddress($address, "ETAP Centre");
$mail->Subject = 'Message via the ETAP Centre website from '.$field_fullname;
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$mail->AddAttachment(""); // attachment
$mail->AddAttachment(""); // attachment
$sent = $mail->Send();
if($sent)
{
header("location:yoururl");
}
else
{
header("location:yoururl");
}
Just repeat the block that starts with $mail = new PHPMailer(); // defaults to using php "mail()" with the Company email address as the recipient before your Message Failed if statement. and just include the fields you want to send (i.e. name, email and message).
Alternatively, if you'd like, you can send a copy of the same exact email by adding the Company email address as a BCC on the email, by adding $mail->AddBCC
The answer was achieved by changing the variable $mail in the second email to $mail2 and adding mail2 = clone $mail;. This allows the user full control over the two emails with optional attachments in both as well as using variables captured by the form in either email. Thanks for your help! :)
<?php
$field_fullname = $_POST['cf_mercury']; // cf_name is a convention used by the HTML form
$field_email = $_POST['cf_jupiter'];
$field_message = $_POST['cf_uranus'];
require_once('class.phpmailer.php');
// E-Mail to Client
$mail = new PHPMailer(); // defaults to using php "mail()"
$body = "Thank you for contacting the whoever";
$mail->SetFrom('company#address.co.uk', 'Enter Sender Name');
$mail->AddReplyTo('company#address.co.uk', 'Enter Sender Name');
$address = $field_email;
$mail->AddAddress($address, $field_fullname);
$mail->Subject = 'Auto-Response: Thank you for contacting the ETAP Centre, '.$field_fullname;
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$mail->AddAttachment(""); // attachment
$mail->AddAttachment(""); // attachment
$sent = $mail->Send();
// E-Mail to Company
$mail2 = clone $mail;
$mail2 = new PHPMailer(); // defaults to using php "mail()"
$body = $field_message;
$mail2->SetFrom($field_email, $field_fullname);
$mail2->AddReplyTo($field_email, $field_fullname);
$address = "company#address.co.uk";
$mail2->AddAddress($address, "Enter Recipient Name");
$mail2->Subject = 'Message via the NAME website from '.$field_fullname;
$mail2->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail2->MsgHTML($body);
$mail2->AddAttachment(""); // attachment - leave incase they are needed in the future
$mail2->AddAttachment(""); // attachment
$sent = $mail2->Send();
if($mail_status) {
{ ?>
<script language="javascript" type="text/javascript">
alert('fail');
window.location = 'index.html';
</script>
<?php
}
} else {
?>
<script language="javascript" type="text/javascript">
alert('success');
window.location = 'index.html';
</script>
<?php
}
?>

How to do email form with multiple recipients and different body?

i have one contact form, when user submit all value will send(email) to admin.But now i want to do when user submit admin will receive the email and user also will receive an email but with different body.
here my previous code :
<?php
if(md5($verif_box).'a4xn' == $_COOKIE['tntcon']){
$name= $_POST["name"];
$email= $_POST["email"];
$phone= $_POST["phone"];
$company= $_POST["company"];
$message= $_POST["message"];
require_once('lib/class.phpmailer.php');
$mail = new PHPMailer(); // defaults to using php "mail()"
$mail->AddReplyTo("admin#gmail.com","I Concept");
$mail->SetFrom('admin#gmail.com', 'I Concept');
$mail->AddReplyTo("admin#gmail.com","I Concept");
$address = "admin#gmail.com";
$mail->AddAddress($address, "I Concept");
$mail->Subject = "MY - Request a Quote";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->Body = "<strong>Request a Quote from I Concept Malaysia Website</strong><br><br>
Name : $name<br>
Email : $email<br>
Phone : $phone<br>
Company : $company<br>
Enquiry : $message<br> <br>
Thank You!<br>
";
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!<br>";
}
}
?>
Try the following. Didn't test but you basically need to get another PHPMailer object going and set the body and to information separately.
$address = "admin#gmail.com";
$mail->Subject = "MY - Request a Quote";
// keeps the current $mail settings and creates new object
$mail2 = clone $mail;
// mail to admin
$mail->AddAddress($address, "I Concept");
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->Body = "<strong>Request a Quote from I Concept Malaysia Website</strong><br><br>
Name : $name<br>
Email : $email<br>
Phone : $phone<br>
Company : $company<br>
Enquiry : $message<br> <br>
Thank You!<br>";
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!<br>";
}
// now send to user.
$mail2->AddAddress($email, $name);
$mail2->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail2->Body = "Separate email body for user filling form out.";
if(!$mail2->Send()) {
echo "Mailer Error: " . $mail2->ErrorInfo;
} else {
echo "Message sent!<br>";
}
Cloning the PHPmailer object is not necessary. Just use the ClearAllRecipients method that is built into PHPmailer before changing the body and sending the second email.
I'm sure you can't send different bodies in one SMTP call. However you can just send the first email and initiate a new PHPMailer.

PHPMailer wont send to email with Hyphen IE-#blah-blah.com

I have a simple contact form that uses PHPMailer to send it's information to the admin. Everything works fine when the results are sent to an e-mail with out a hypen such as blah#blah.com. As soon as I change the address to an e-mail with a hypen like blah#blah-blah.com, I get this error.
"Could not instantiate mail function. Mailer Error: Could not instantiate mail function."
Is this a bug with PHPMailer?
Here's my code
<?php
require_once('class.phpmailer.php');
$question_for = $_POST['question_for'];
$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$company = $_POST['company'];
$comment = $_POST['comment'];
$mail = new PHPMailer(); // defaults to using php "mail()"
$body = eregi_replace("[\]",'',$body);
$mail->AddReplyTo("donotreply#blah-blah.com","DoNotReply");
$mail->SetFrom('donotreply#blah-blah.com', 'DoNotReply');
switch ($question_for) {
case "Sales":
$address = "Sales#blah-blah.com";
$mail->AddAddress($address, "Blah");
$mail->Subject = "Message from Sales";
break;
case "Service":
$address = "service#blah-blah.com";
$mail->AddAddress($address, "Blah");
$mail->Subject = "Message from Service";
break;
case "Career":
$address = "career#blah-blah.com";
$mail->AddAddress($address, "Blah");
$mail->Subject = "Message from Career";
break;
}
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML("
Question For:".$question_for."<br />
Name:".$name."<br />
Phone:".$phone."<br />
Email:".$email."<br />
Company:".$company."<br />
Comment:".$comment."<br />");
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
header('Location: http://blah.com/contact/?sent');
}
?>
Checking even more, I see that this works
<?php
mail("test#blah.com", "Test Email", "Testing"); ?>
but this does not
<?php
mail("test#blah-blah.com", "Test Email", "Testing"); ?>

Categories