I have a small php website that sends a text message to any given number in US. I tried sending my self a text using it but didn't receive it. I sent it to my cousin's number and he received it. I am using Simple Mobile as my carrier and my cousin uses T-mobile. Could it be that somehow this message is being converted to short message? If so, is there any way I can fix it ? Because in future, I will need to send text messages to any given number and it would be nice if all intended recipients receive the texts without having to enable any thing.
Here is my code :
require 'PHPMailer-master/PHPMailerAutoload.php';
// Instantiate Class
$mail = new PHPMailer();
// Set up SMTP
$mail->IsSMTP(); // Sets up a SMTP connection
$mail->SMTPDebug = 2; // This will print debugging info
$mail->SMTPAuth = true; // Connection with the SMTP does require authorization
$mail->SMTPSecure = "tls"; // Connect using a TLS connection
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->Encoding = '7bit'; // SMS uses 7-bit encoding
// Authentication
$mail->Username = "example#gmail.com"; // Login
$mail->Password = "password"; // Password
// Compose
$mail->Subject = "Testing"; // Subject (which isn't required)
$mail->Body = "Testing"; // Body of our message
// Send To
$mail->AddAddress( "phoneNumber#tmomail.net" ); // Where to send it
var_dump( $mail->send() ); // Send!
Related
I need to connect to the GMAIL SMTP server with email and password, without sending email and then receiving 200 OK.
I using the code PHPMailer:
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
$mail->Host = "smtp.gmail.com";
$mail->Port = 465; // or 587
$mail->IsHTML(true);
$mail->Username = "myuser#gmail.com";
$mail->Password = "password";
$mail->SetFrom("");
$mail->Subject = utf8_decode("My subject");
$mail->Body = "hello";
$mail->AddAddress("destination#gmail.com");
$mail->Body = template('emails/reset-password', compact('comentario'));
if ($mail->Send()) {
$mail->ClearAllRecipients();
$mail->ClearAttachments();
}
My script is sending email, I would just like to validate the authentication.
PHPMailer itself isn't much use for this as it's all about the sending. However, the SMTP class that's part of PHPMailer can do this just fine, and there is a script provided with PHPMailer that does exactly as you ask. I'm not going to reproduce the script here as it just creates maintenance for me!
The script connects to an SMTP server, starts TLS, and authenticates, and that's all.
I'm using PHPMailer to send text messages. This is working. However, the messages come with S: and M: at the begging of the messages. S: is for Subject and M: is for Message.
I've used both mail() and PHPMailer to send my messages. Both methods include S and M.
My code is below. How can I send messages with PHP without S and M showing up?
require('_includes/PHPMailer/PHPMailerAutoload.php');
// Instantiate Class
$mail = new PHPMailer();
// Set up SMTP
$mail->IsSMTP(); // Sets up a SMTP connection
$mail->SMTPDebug = 2; // This will print debugging info
$mail->SMTPAuth = true; // Connection with the SMTP does require authorization
$mail->SMTPSecure = "tls"; // Connect using a TLS connection
$mail->Host = "smtp.sparkpostmail.com";
$mail->Port = 587;
$mail->Encoding = '7bit'; // SMS uses 7-bit encoding
// Authentication
$mail->Username = "username"; // Login
$mail->Password = "password"; // Password
$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
// Compose
$mail->Subject = ""; // Subject (which isn't required)
$mail->Body = "Testing"; // Body of our message
// Send To
$mail->AddAddress( "myphonenumber#email.uscc.net" ); // Where to send it
echo '<pre>';
var_dump( $mail->send() ); // Send!
echo '</pre>';
I'm trying to create a mailing system for our library. People receive an e-mail when they requested a book. However, I want them to receive an e-mail one day before the hand-in date as well.
So I'm not looking for a sleep script code, I'm looking for a code that can maybe store the data on the server until the hand-in date arrived.
I'm using Joomla 3.5.1 for our website, this is the code for the PHPMailer:
jimport('joomla.mail.mail');
try{
$mail = new PHPMailer();
$body = $mailmsgadmin;
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "example.host.com"; // SMTP server
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "example.host.com"; // sets the SMTP server
$mail->Port = 25; // set the SMTP port for the GMAIL server
$mail->Username = "email"; // SMTP account username
$mail->Password = "password"; // SMTP account password
$mail->SetFrom('email', 'First Last');
$mail->AddReplyTo($mailuseremail, $mailusername);
$mail->Subject = $mailsubject;
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
$mail->MsgHTML($body);
$mail->AddAddress("Users e-mail","Users name");
if(!$mail->Send()) {
JError::raiseWarning( 'SOME_ERROR_CODE', $mail->ErrorInfo);
}
} catch (Exception $e) {JError::raiseWarning( 'SOME_ERROR_CODE', $e->getMessage());}
Instead of trying to get PHPMailer delay the sending, add your email details to a database table. And then write a cron job that checks the table for emails that need to be sent.
I am using PHPmailer github, I use the "gmail.php" from the examples and it works perfect when I open it in my browser. But when I copy the code and add it to my existing signup script I get an 500 Error. Also when I try to include it I get an 500 Error. How can I add phpmailer to my existing signup script?
<?php
/**
* This example shows settings to use when sending via Google's Gmail servers.
*/
//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don't have access to that
date_default_timezone_set('Etc/UTC');
require '../PHPMailerAutoload.php';
//Create a new PHPMailer instance
$mail = new PHPMailer;
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 2;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = 'xxxxxx';
// use
// $mail->Host = gethostbyname('smtp.gmail.com');
// if your network does not support SMTP over IPv6
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 587;
//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'tls';
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = "xxxxxx";
//Password to use for SMTP authentication
$mail->Password = "xxxxxxxxxxxxx";
//Set who the message is to be sent from
$mail->setFrom('xxx', 'xxx');
//Set an alternative reply-to address
$mail->addReplyTo('xx', 'xx');
//Set who the message is to be sent to
$mail->addAddress('Txxx', 'John Doe');
//Set the subject line
$mail->Subject = 'Welcome to xx!';
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
if (!$mail->send()) {
} else {
}
The following code gives the message
Mailer Error: SMTP Error: The following SMTP Error: Data not accepted. But when I replace $EmailAdd with a a#yahoo.com. The mail was sent.
What's wrong with my code? I'm kind of new in php, especially in dealing with mail functions.
$sql1 = "SELECT Email_Address FROM participantable where IDno=$studId";
$result1 = mysql_query($sql1);
while ($row1 = mysql_fetch_assoc($result1)){
$EmailADD = $row1["Email_Address"];
}
//error_reporting(E_ALL);
error_reporting(E_STRICT);
date_default_timezone_set('America/Toronto');
include("class.phpmailer.php");
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
$mail = new PHPMailer();
$body = $mail->getFile('contents.html');
$body = eregi_replace("[\]",'',$body);
$mail->IsSMTP();
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "jsbadiola#gmail.com"; // GMAIL username
$mail->Password = "********"; // GMAIL password
$mail->AddReplyTo("jsbadiola#gmail.com","Lord Skyhawk");
$mail->From = "jsbadiola#gmail.com";
$mail->FromName = "Update";
$mail->Subject = "PHPMailer Test Subject via gmail";
$mail->Body = "Hi,<br>This is the HTML BODY<br>"; //HTML Body
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->WordWrap = 50; // set word wrap
$mail->MsgHTML($body);
$mail->AddAddress($EmailADD, "Agta ka");
$mail->AddAttachment("images/phpmailer.gif"); // attachment
$mail->IsHTML(true); // send as HTML
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
$status = "Successfully Save!";
header("location: User_retsched.php?IDno=$studId&status=$status&Lname=$Lname&Fname=$Fname&Course=$Course&Year=$Year");
}
Most times I've seen this message the email gets successfully sent anyway, but not always. To debug, set:
$mail->SMTPDebug = true;
You can either echo the debug messages or log them using error_log():
// 'echo' or 'error_log'
$mail->Debugoutput = 'echo';
A likely candidate especially on a heavily loaded server are the SMTP timeouts:
// default is 10
$mail->Timeout = 60;
class.smtp.php also has a Timelimit property used for reads from the server.
It also helps if you have not exceeded your daily sending limit of Googles Spam inforcement.
check you query to the db output & variable value at that point in the script. make sure it's returning the desired value for $EmailADD .
do a var_dump($EmailADD, true);
or try to echo somewhere the output of that query. If your actually receiving an email value from that query, I don't see why it shouldn't work, specially when you mention that assigning a value directly works; without sql query.
Try a different SMTP server? See if that works?
Or just don't use an smtp server, most servers with PHP on also have sendmail/postfix, so can relay email themselves.
remove this bit ...
$mail->IsSMTP();
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "jsbadiola#gmail.com"; // GMAIL username
$mail->Password = "alucar"; // GMAIL password