I need to send form data to mail in tabular format. for this i'm using using PHPMailer. when I am trying to display values that are selected by user it only display as array. can somebody help me to find what is wrong in this code?
Below is the part of HTML
<input type="checkbox" name="Favorite_Drink[]" value="Vodka">Vodka
<input type="checkbox" name="Favorite_Drink[]" value="Vodka">Vodka
<input type="checkbox" name="Favorite_Drink[]" value="Bear">Bear
Here is PHP part
$Favorite_Drink = $_POST['Favorite_Drink'];
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'd11288#gmail.com'; // SMTP username
$mail->Password = 'pass'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom('a11288#gmail.com', 'User');
$mail->addAddress('al#gmail.com', 'Joe User'); // Add a recipient
//$mail->addAddress('ellen#example.com'); // Name is optional
$mail->addReplyTo('a11288#gmail.com', 'Information');
$mail->addCC('a11288#gmail.com');
//$mail->addBCC('bcc#arshad.com');
$mail->Subject = 'Here is the subject';
//$mail->Body = "Name of patient is ";
//$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$mail->isHTML(true);
$mail->Subject = ' Test';
$mail->Body = <<<EOF
<html><body>
<br>
<table rules="all" style="border-color: #666;" cellpadding="10">
<tr style='background: #eee;'>
<td>Favorite_Drink </td>
<td> $Favorite_Drink</td>
</tr>
</table>
</body>
</html>
EOF;
//Altbody is used to display plain text message for those email viewers which are not HTML compatible
$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';
}
}
}
$Favorite_Drink = $_POST['Favorite_Drink']; - this variable gets array of data from form.
<td> $Favorite_Drink</td> - if you want print array as text you should, use something like this implode(', ', $Favorite_Drink)
Related
I am using corephp and i have used hostgator webmail to send email. Email is successfully going to some testing email provider like mailinator but it is not going to gmail,outlook and company email id.It is not in spam/junk as well. There is no error message recorded and it does not create any exception while sending email.
I am not getting what could be the reason?
This is my actual code.
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isMail(); // Set mailer to use SMTP
$mail->Host = 'http://********/webmail'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'username'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
$mail->From = 'from#example.co';
$mail->FromName = 'Mailer';
$mail->addAddress('To#mailinator.com', 'ToUser'); // Add a recipient
$mail->addAddress('To#mailinator.com'); // Name is optional
$mail->addReplyTo('To#mailinator.com', 'Information');
$mail->addCC('cc#example.com');
$mail->addBCC('bcc#example.com');
$mail->WordWrap = 50; // Set word wrap to 50 characters
$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$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';
}
Remove This Line from your coding
$mail->addAddress('To#mailinator.com');
You Can Test With Gmail Account you will get mail on your junk mail box. you can report that mail as not a junk mail then you will get mails on outlook.
E.g:
$mail->addAddress('Toemailname#gmail.com', 'ToUser');
Here is my code
$form_message .= "Application_Comments" . "\r\n";
ini_set('your_email', 'testsupport#example.com');
$to = "xyz#gmail.com";
$subject = "Collaboration";
$your_email = 'testsupport#example.com';
$headers = "From: $your_email" . "\r\n";
$headers .= "Cc:abc#yahoo.com,efg#gmail.com"."\r\n";
$headers .= "Reply-To: $your_email" . "\r\n";
if(mail($to,$subject,$form_message,$headers))
{
echo " Delete Mail Sent Successfully";
}
else
{
echo "Delete Mail not sent";
}
if I execute above code I am not receiving any mail even 'To' mail is also not getting.
If I use one mail address in cc I am getting mail, but 'To' mail was not received
can any one help me on this?
You should consider using the popular PHPMailer class to handle email needs in PHP. It makes sending emails with multiple TOs, CCs, BCCs and REPLY-TOs easily achieved. It even let's you easily add attachments to your emails. Download the ZIP from Github, and extract it to the directory it will be used in.
<?php
require '/path/to/PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'user#example.com'; // SMTP username
$mail->Password = 'secret'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom('from#example.com', 'Mailer');
$mail->addAddress('joe#example.net', 'Joe User'); // Add a recipient
$mail->addAddress('ellen#example.com'); // Name is optional
$mail->addReplyTo('info#example.com', 'Information');
$mail->addCC('cc#example.com');
$mail->addBCC('bcc#example.com');
$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$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';
}
?>
The isHTML is already set to True. But it doesnt work in the email i receive. I just get the sample html from a tutorial.
<?php
require("phpmailertest/class.phpmailer.php");
$x=$_SESSION['items'];
$mail = new PHPMailer();
$mail->IsSMTP(); // set mailer to use SMTP
// $mail->SMTPDebug = 2;
$mail->From = "benedictpayot#gmail.com";
$mail->FromName = "BravoTech Solutions";
$mail->Host = "smtp.gmail.com"; // specif smtp server
$mail->SMTPSecure= "ssl"; // Used instead of TLS when only POP mail is selected
$mail->Port = 465; // Used instead of 587 when only POP mail is selected
$mail->SMTPAuth = true;
$mail->Username = "benedictpayot#gmail.com"; // SMTP username
$mail->Password = "Ichthys030313!"; // SMTP password
$mail->AddAddress($_SESSION['email_address']);
$mail->IsHTML(true);
$mail->Subject = "Mail Test";
$mail->Body = '<html><body>';
$mail->Body = '<table style="border-color: #eee;"';
$mail->Body = '<tr>
<td>JALOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
<td>OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
<tr>
<td>BENEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEDICT
<td>PAYOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOT
</table>';
$mail->WordWrap = 50;
if(!$mail->Send()) {
echo 'Message was not sent.';
session_destroy();
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}
?>
You can set Body (and AltBody) manually to any value you like. msgHTML() is a convenience function to set moth of them and optionally apply an html to text conversion to generate your plain text version. It also sets isHTML, rewrites image URLs and various other things - but you don't have to use it.
In your code you're saying:
$mail->Body = '<html><body>';
$mail->Body = '<table style="border-color: #eee;"';
$mail->Body = '<tr>...
Which should be:
$mail->Body = '<html><body>';
$mail->Body .= '<table style="border-color: #eee;"';
$mail->Body .= '<tr>...
otherwise you're just overwriting the contents of Body each time.
You should base your code on the gmail example bundled with PHPMailer - it looks like you are using an old one from somewhere else.
I'm not sure (correct me if I'm wrong) but I was always setting body like this:
$mail->MsgHTML($body);
My code is this.
<html>
<head>
<title>Sending email using PHP</title>
</head>
<body>
<?php
$to = "myemail#gmail.com";
$subject = "This is subject";
$message = "This is simple text message.";
mail($to,$subject,$message);
echo "<br>Message sent successfully...";
?>
</body>
</html>
I know this is very simple but I am not able to solve it my try to help me
Is there a mailserver running on the machine that hosts this page? Most likely not because the code you show should work.
Now there are two options: Install a mailserver or use an additional PHP library to overcome this problem. I'm not gonna post a tutorial on how to install a mailserver so just Google it!
For the PHP library part, u could use PHPMailer. This class holds additional settings for sending the mail via specific servers. First download the needed files from GitHub (on the right side, click "Download zip") https://github.com/PHPMailer/PHPMailer . Unzip the package and copy the files to your working directory. The code could be like:
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'user#example.com'; // SMTP username
$mail->Password = 'secret'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->From = 'from#example.com';
$mail->FromName = 'Mailer';
$mail->addAddress('joe#example.net', 'Joe User'); // Add a recipient
$mail->addAddress('ellen#example.com'); // Name is optional
$mail->addReplyTo('info#example.com', 'Information');
$mail->addCC('cc#example.com');
$mail->addBCC('bcc#example.com');
$mail->WordWrap = 50; // Set word wrap to 50 characters
$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$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';
}
?>
The easiest way to send mail is to use a gmail account or something. The settings can be found literally everywhere. For example: http://phpmailer.worxware.com/?pg=examplebgmail
I'm using this code to try and get PHPmailer to send emails to people who use my website as gmail has blocked me from using php mail() apparently. However, It returns the error Mailer Error: SMTP Error: The following recipients failed: myemail#gmail.com
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'myhost'; // Specify main and backup server
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'site email'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
$mail->From = 'site email';
$mail->addAddress('myemail#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';
Can someone help me fix this problem?
mail($to, $subject,$message, $headers, "-fSENDEREMAILID");
try to add -f before the sender email id in the mail function and it works i guess