Good day! I have tried and search everything I can find.. but to no avail, code is still not working, and I'm not even getting any error message. I have no problem with my variables, it is in the "mail" part i think. Please help.
require "Mail.php";
$from = 'angelsofmaryacademy#gmail.com';
$to = $hidden1;
$subject = $hidden2;
$body = $_POST['replytomsg'];
$host = "smtp.gmail.com";
$port = "465";
$user = "angelsofmaryacademy#gmail.com";
$pass = "Ang3lsofmaryacademy";
$headers = array ("From" => $from, "To" => $to, "Subject" => $subject);
$smtp = #Mail::factory("smtp",array(
"host" => $host,
"port" => $port,
"auth" =>true,
"username" => $user,
"password" => $pass));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo ('<p>'. $mail->getMessage() . '</p>');
}
else {
echo ('<p>Message successfully sent! </p>');
}
}
Related
I have PHP Send Email using SMTP.
$from = "Info <donotreply#test.com>";
$subject = "Calibration will be expiring!";
$body = 'Hello';
$to = "david#test.com, dono#test.com";
$cc = "rena#test.com";
$bcc = ""; //sometimes BCC can be empty
$host = 'smtp.test.com';
$port = '587';
$username = 'donotreply#test.com';
$password = 'dontreply?';
$headers = array(
'Port' => $port,
'From' => $from,
'To' => $to,
'Subject' => $subject,
'Content-Type' => 'text/html; charset=UTF-8',
'Cc' => $cc
);
$recipients = $to.", ".$bcc.", ".$cc;
$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($recipients, $headers, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
I tried to run above code and only working if $bcc is not empty.
Error when $bcc is empty
Failed to add recipient: #localhost [SMTP: Invalid response code received from server (code: 501, response: 5.1.3 Invalid address [HKXPR02MB0695.apcprd02.prod.outlook.com])]
Is there any way how to fix it or need some modification there?
If $bcc variable is empty then your concatenated string contains ,, which is syntactically incorrect. You need to add some logic there to make ensure this is not happening.
Also I doubt you set BCC correctly anyway. It should not be just another recipient like you have now.
I've got the solution below:
$bcc = $dEmailListBCC['EMAIL_ADDRESS'];
if($bcc == "")
{
$a = "";
}
else
{
$a = ",".$bcc;
}
First, check the $bcc variable is empty or not.
and then the recipients to be like this:
$recipients = $to." ".$a.", ".$cc;
This seems to not work. My webhost claims to have PEAR installed. Does anybody spot any mistakes? I do have every var/field correct. But yet, when this runs, it stops the loading of the rest of the php html page.
<?php
// Report all PHP errors
error_reporting(-1);
if (isset($_POST['email'])) {
require_once "Mail.php";
$from = "No Reply <redacted#redacted.redacted>";
$to = "redacted";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
$host = "redacted.redacted.redacted";
$username = "redacted#redacted.redacted";
$password = "---";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp -> send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail -> getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
}
?>
Having troubles sending email throw php on centos 6.7 with cpanel installed.
I assume the problem with Mail.php reference path but I don't know how to correct it. The mail.php file located here: /home/userfolder/php/Mail.php (I have installed the following PEAR packages: Auth_SASL, Mail, Net_SMTP, Net_Socket)
The error which I get is:
Fatal error: Class 'Mail' not found in home/userfolder/public_html/_sendmail.php on line 14
<?php
ini_set("include_path", '/home/userfolder/php:' . ini_get("include_path") );
$from = "Sandra Sender <info#domain.com>";
$to = "Ramona Recipient <info#domain.com>";
$subject = "Email";
$body = "Hi,\n\nHow are you?";
$host = "mail.domain.com";
$username = "username";
$password = "password";
$headers = array ('From' => $from, 'To' => $to, 'Subject' => $subject);
$smtp = Mail::factory('smtp', array ('host' => $host, 'auth' => true, 'username' => $username, 'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail))
{ echo("<p>" . $mail->getMessage() . "</p>");
} else
{
echo("<p>Message successfully sent!</p>");
}
?>
Add into begin of file
require_once dirname(dirname(__FILE__)) . '/Mail.php';
I'm having trouble getting an email address from $_GET.
Here is my code:
<?php
$eadd = $_GET['email'];
echo("<p>Please check your inbox on your email $eadd.</p>");
?>
I went to this link:
http://localhost/file.php?email=myemail#company.com
Yet the output is only:
Please check your inbox on your email .
EDIT
Here's my complete code :
<?php
require_once "Mail.php";
//Get link posted info's needed
//Email
$eadd = $_GET['email'];
$from = "OtakuJam Registration <no-reply#comp.com>";
$to = " $unick < $eadd >";
$subject = "Thank you for registering";
$body = "Dear $unick ,
\n Thank you for registering to OtakuJam. To activate your account, \n
";
$host = "mail.srv.com";
$username = "name#comp.com";
$password = "mypass";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Please check your inbox on your email $eadd.</p>");
}
?>
`Please ignore the $unick there, also the mail won't send unless i put an email on the code instead of < $eadd >
turning my $to syntax to $to = $unick . "<" . $eadd . ">"; as #Charlie gave me helped me. Also to those who told me to use ".$variable.". to my echo helped. thanks
This code is working fine in my unix shared hosting account but how do I attach file with it?
I've removed the hostname, login, passwd etc.
<?php
require_once "Mail.php";
$from = "contactus#site.com";
$to = "to email id";
$subject = "this is the message from your domain";
$body = "give your message body here";
$host = "mail.site.com";
$username = "user";
$password = "pass123";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) { echo("" . $mail->getMessage() . "");
} else {
echo("Message Sent successfully ");
}
?>
You have to include both PEAR::Mail and PEAR::Mail_Mime, as it takes both classes to get the full email sent. Example...
include_once('Mail.php');
include_once('Mail_Mime/mime.php');
// include_once('Mail/mime.php');
// The code below composes and sends the email
$message = new Mail_mime();
$message->setTXTBody($text);
$message->addAttachment($path_of_attachment_file);
$body = $message->get();
$extraheaders = array("From"=>$from, "Subject"=>$subject,"Reply-To"=>$visitor_email);
$headers = $message->headers($extraheaders);
$mail = Mail::factory("mail");
$mail->send($to, $headers, $body);