I have a form that basically has 3 radio buttons that will let you pick a staff member you want to get in contact with. The form requires a name, email and message. I cannot find where it tells me what the error is. I have debugging on but do not know where the error is coming from.
My goal is to have it so that the person they select will be emailed and when the email is sent it will be redirected to a page that has the correct staff members info on it. However for the life of me I cannot get this to work. I believe everything works correct but when I inserted the code that I found on SO to connect to the SMTP servers and email the contact form input my formProcess.php breaks.
EDIT: With the help of some of you here I have found the solution to 2 of the errors I am getting. However now that I have fixed these errors I am getting a different error. I am now receiving this:
2015-12-23 04:42:59 SMTP ERROR: Failed to connect to server: Cannot allocate memory (12) 2015-12-23 04:42:59 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting 2015-12-23 04:42:59 SMTP ERROR: Failed to connect to server: Cannot allocate memory (12) 2015-12-23 04:42:59 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Warning: Cannot modify header information - headers already sent by (output started at /www/contact/phpmailer/class.smtp.php:234) in /www/contact/formProcess.php on line 80
EDIT 2: I have uploaded it to my hosted server. It has solved the error mentioned above. I now have an issue with the password failing, even though I have signed in using the password I am using in the code. Instead of copy/pasting the error message you can see it live on my site for yourself.
EDIT 3: I just noticed that there is an email from Gmail that says "Someone tried to sign in to your Google Account from an app that doesn't meet standard security standards." This can't be a coincidence can it? Is this why I cannot connect? and if so what can I do to meet security standards?
EDIT 4: I have now got everything working fine except for 2 things. 1, for some reason it is sending the emails twice. I am not sure why but I feel like I can figure it out. The real issue I am having now is that I now want to include Googles reCAPTCHA to my form as well. Everything works fine until I added this bit of code that I thought would verify if the reCAPTCHA was successful and if it wasn't just add an error to my code, but after I entered the code below to do that my code breaks.
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'https://www.google.com/recaptcha/api/siteverify',
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => [
'secret'=>'Well it says secret for a reason!',
'response'=> $_POST['g-recaptcha-response']
]
]);
$response = json_decode(curl_exec($curl));
if (!$response->success){
$errors[] = 'There was a problem with reCAPTCHA, please try again.';
};
And bellow is all code that processes the form.
<?php
session_start();
ini_set('display_errors', 1); error_reporting(E_ALL);
require_once 'PHPMailerAutoload.php';
$errors = [];
$toWho ='';
if(isset($_POST['name'], $_POST['email'], $_POST['message'], $_POST['who'])){
$fields = [
'name' => $_POST['name'],
'email' => $_POST['email'],
'message' => $_POST['message'],
'who' => $_POST['who']
];
foreach($fields as $field => $data) {
if(empty($data)) {
$errors[] ='The ' .$field. ' field is required.';
}
}
if ($fields['who'] == "staff1") {
$toWho = 'staff1#domain.com';
} else if ($fields['who'] == "staff2") {
$toWho = 'staff2#domain.com';
} else {
$toWho = 'staff3#domain.com';
}
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'https://www.google.com/recaptcha/api/siteverify',
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => [
'secret'=>'Well it says secret for a reason!',
'response'=> $_POST['g-recaptcha-response']
]
]);
$response = json_decode(curl_exec($curl));
if (!$response->success){
$errors[] = 'There was a problem with reCAPTCHA, please try again.';
};
if(empty($errors)) {
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPAuth = true;
$mail->smtpSecure = 'tls';
$mail->Port = 587;
// $mail->SMTPDebug = 3;
$mail->Host = 'mailen3.cloudsector.net';
$mail->From = "No-reply#domain.com";
$mail->Username = 'No-Reply#domain.com';
$mail->Password = 'PAsswoRD';
$mail->SetFrom("No-reply#domain.com", "No Reply" );
$mail->AddReplyTo($fields['email'], $fields['name']);
$mail->AddAddress($toWho, $fields['who']);
$mail->Subject = $fields['name'] . ' wants to talk!';
$mail->Body = 'From: ' .$fields['name']. ' (' .$fields['email']. ') ' .$fields['message']. ;
$mail->send();
if($mail->send()) {
header('Location: ../../' .$fields['who']. 'thanks.php');
die();
}else {
$errors[] = 'Sorry! Something went wrong and your message could not be sent. Please try again ';
}
}
} else {
$errors[] = 'Something went wrong.';
}
$_SESSION['errors'] = $errors;
$_SESSION['fields'] = $fields;
header('Location: index.php');
?>
Try displaying errors by adding the following code at the top of your script:
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
If you're getting a server error 500, Try commenting out small blocks of code until the script works. That way you can identify the problem.
Related
I am trying to get this mail sent on registration using SwiftMailer, however it keeps throwing this error.
I am using this add-on for osCommerce:
http://addons.oscommerce.com/info/901
I have followed the exact instructions as per what he said. Also added permissions still the same thing.
I am posting the code below:
CODE:
if (EMAIL_TRANSPORT == 'smtp') {
include_once(DIR_FS_CATALOG.DIR_WS_CLASSES . 'SwiftEmailer/swift_required.php');
$body = $this->html;
$body = preg_replace("[]",'',$body);
$host_name = explode('://',EMAIL_SMTP_HOST_SERVER);
if(count($host_name)>1){
$transport = Swift_SmtpTransport::newInstance($host_name[1], EMAIL_SMTP_PORT_SERVER, $host_name[0])
->setUsername(EMAIL_SMTP_USERNAME)
->setPassword(EMAIL_SMTP_PASSWORD);
} else {
$transport = Swift_SmtpTransport::newInstance(EMAIL_SMTP_HOST_SERVER, EMAIL_SMTP_PORT_SERVER)
->setUsername(EMAIL_SMTP_USERNAME)
->setPassword(EMAIL_SMTP_PASSWORD);
}
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance($subject)
->setFrom(array($from_addr => $from_name))
->setTo(array($to_addr => $to_name))
->setMaxLineLength(50);
if($body){
$message->setBody($body, 'text/html', CHARSET);
}
if($this->text){
$message->setBody($this->text, 'text/plain', CHARSET);
}
else{
$message->setBody($this->html_text, 'text/html', CHARSET);
}
$mailer->send($message);
}
If anyone could help me sort out this issue that would be great. Thank you
I'm bringing the (Laravel-based) website for an event that's coming up soon, up to date. Part of this was improving the mailing function, for which I decided to use Mandrill's SMTP with SwiftMailer. Everything worked perfectly while working locally. However, since we pushed everything to a live (well, testing, but on the same server as live) staging area, no mails get sent anymore.
Everything seems to break down after I make a send() command in PHP. Even a simple print command doesn't do anything. There's also no errors being reported, except if I go look in my console, where the request returns a 500 Internal Server Error, without any other errors.
At the moment, these are the function I'm using only to test, which works and sends perfectly on local and then prints, but just gives a white screen on the staging area...
Route::any('test', function()
{
testMail();
//this print works perfectly locally but shows nothing on staging
print ('boe');
});
function testMail(){
$to = array('private#email.address' => 'My Name');
$subject = 'test mail';
$text = "test mail hier";
$htmlTekst = "<b>boe</b><i>spaghetti</i>";
$view = View::make('mailTemplate',
['naam' => 'Jeroen Cuvelier',
'tekst' => $htmlTekst,
'username' => 'my email address',
'password' => 99999,
'siteUrl' => rootUrl(),
'header2' => '']);
$html = $view->render();
sendEmail($text, $html, $to, $subject, "", "");}
function sendEmail($text, $html, $to, $subject, $attachment, $attachmentName)
{
//$subject = 'Subject!';
$from = array('event#email.company' =>'Company event');
/*
SMTP-settings
*/
$transport = Swift_SmtpTransport::newInstance('smtp.mandrillapp.com', 25);
$transport->setUsername('MY_MANDRILL_USERNAME');
$transport->setPassword('MY_MANDRILL_PASSWORD');
$swift = Swift_Mailer::newInstance($transport);
$message = new Swift_Message($subject);
$message->setFrom($from);
$message->setBody($html, 'text/html');
$message->setTo($to);
$message->addPart($text, 'text/plain');
if ($attachment != "")
{
$toAttach = Swift_Attachment::fromPath($attachment);
if ($attachmentName!="")
{
$toAttach->setFilename($attachmentName);
}
$message->attach($toAttach);
}
//neither of these messages print on staging
if ($recipients = $swift->send($message, $failures))
{
echo 'Message successfully sent!';
} else {
echo "There was an error:\n";
print_r($failures);
}
}
Turns out the problem was not in PHP or anything I had done. The server just didn't allow SMTP calls. A call to the company hosting that fixed my issues.
I'm sending SMS by PHP, SMPP protocol and must use Net_SMPP library. After sending SMS (it comes to phone normally) I need to receive answer (deliver_sm PDU from SMSC). But listening of it hasn't take effect. My reciver's code:
$host = '*********';
$port = '****';
$login = '*****';
$password = '*******';
/*
* There is sending of SMS
*/
$smsc = new Net_SMPP_Client($host, $port);
$smsc->connect();
$resp = $smsc->bind(
array(
'system_id' => $login,
'password' => $password,
'addr_ton' => NET_SMPP_TON_INTL,
'addr_npi' => NET_SMPP_NPI_ISDN,
'system_type' => ''
),
$typeBind
);
if (!is_object($resp) || $resp->isError()) {
die('CANNOT BIND');
}
$resp = $smsc->readPDU();
if (is_object($resp) && !$resp->isError()) {
//This is needble point
}
SMS-provider says that he'd sent deliver_sm and my script responded deliver_sm_resp with error "ESME receiver temporary app error code" (errcode 0x00000064).
Intresting that after sending SMS to special "gate"-number deliver_sm will normally come to me and handle by my script.
What did I go wrong? Help me please! Or say me if any other info needs for solving.
SOLVED!
There was other daemon running by same login on other server! It was receiving all requests
Im trying to read mails from a gmail apps account by using Zend Framework. I've just transfered the Zend Framework dir to my server (path: /Zend/library/).
How do I load the Zend Framework and the Mail module? And how do I further read the mail?
I've tried the following with no results:
$path = 'Zend/library/';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);
I believe the syntax for reading the inbox is something like:
$mail = new Zend_Mail_Storage_Imap(array('host' => 'imap.gmail.com', 'user' => "name#domain.com", 'password' => "mypassword", 'ssl' => 'SSL'));
EDIT
The following code works:
$path = 'Zend/library/';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);
require_once 'Zend/Loader/Autoloader.php';
Zend_Loader_Autoloader::getInstance();
$mail = new Zend_Mail_Storage_Imap(array('host' => 'imap.gmail.com',
'user' => 'mail#domain.com',
'password' => 'password',
'ssl' => 'SSL'));
echo $mail->countMessages();`
... but when i try to echo unread emails:
echo "Unread mails:\n";
foreach ($mail as $message) {
if ($message->hasFlag(Zend_Mail_Storage::FLAG_SEEN)) {
continue;
}
// mark recent/new mails
if ($message->hasFlag(Zend_Mail_Storage::FLAG_RECENT)) {
echo '! ';
} else {
echo ' ';
}
echo $message->subject . "\n";
}
I get the following message:
Fatal error: Uncaught exception 'Zend_Mail_Storage_Exception' with message 'cannot login, user or password wrong' in /var/www/zvinx.dk/test/Zend/library/Zend/Mail/Storage/Imap.php:279 Stack trace: #0 /var/www/zvinx.dk/test/gmail.php(11): Zend_Mail_Storage_Imap->__construct(Array) #1 {main} thrown in /var/www/zvinx.dk/test/Zend/library/Zend/Mail/Storage/Imap.php on line 279
It says the username or password is wrong, which is weird cause I didnt change it from when it was working... How come this error occur?
the gmail settings are a little tricky. try:
$mail = new Zend_Mail_Storage_Imap(array('host' => 'imap.gmail.com',
'user' => 'mail#domain.com',
'port' => '993',
'password' => 'password',
'ssl' => 'tls',
'auth' => 'login'
));
NOTE: the gmail are using the SSL/TLS protocol which apparently is different than the standard SSL.
You really don't think that you can start using Zend Framework without reading/learning about the basics of the framework? At least take a look at the quickstart on how to use the framework with the autoloading features and then dive into the Zend_Mail documentation, more specifically the part that says "Reading Mail Messages"
There are the login setting i use to read emails via IMAP and dump attached files
public function imapAction()
{
$config = array('host'=> 'imap.gmail.com',
'user' => 'xx',
'password' => 'xx',
'ssl' => 'SSL',
'port' => 993);//995 pop, imap 993
$mail = new Zend_Mail_Storage_Imap($config);
$maxMessage = $mail->countMessages();
$this->logger->info($maxMessage);
for ($i = $maxMessage; $i <= $maxMessage; $i++)
{
$message = $mail->getMessage($i);
$this->logger->info($i.'Mail from '.$message->from.':'.$message->subject);
if($message->isMultipart())
{
$this->logger->info("has attachments");
$part = $message->getPart(2);
$cnt_typ = explode(";" , $part->contentType);
$name = explode("=",$cnt_typ[1]);
$filename = $name[1];//It is the file name of the attachement in browser
//This for avoiding " from the file name when sent from yahoomail
$filename = str_replace('"'," ",$filename);
$this->logger->info($filename);
$attachment = base64_decode($part->getContent());
$fhandle = fopen($filename, 'w');
fwrite($fhandle, $attachment);
fclose($fhandle);
}
}
}
I had the same issue and this instruction has helped me.
Quit all mail clients that are accessing the affected Gmail account. This means the Mail app on the iPhone and any other place you are accessing your Gmail from such as a computer.
Open browser and navigate to this page: http://www.google.com/accounts/DisplayUnlockCaptcha
Enter your full Gmail address, password and type the characters you see in the picture. Touch the unlock button to verify your account.
Try to read mails from a gmail apps account by using Zend Framework. Your Gmail access should be restored.
If you encounter this error and you are 100% sure about the password you provided it might come from the 2 factor authentication you set on your google account.
Google help gives indications on what to do in this case. I manage to get access to my account by generating an AppPassword in my case
I'm trying to implement PEAR's Mail_Queue package to queue some emails for a web application. I've used the documentation at http://pear.php.net/manual/en/package.mail.mail-queue.mail-queue.tutorial.php to write a small test script.
My problem is that the database is not being updated, and it's not producing errors.
EDIT
// mail_queue db options
$db_options['type'] = 'mdb2';
$db_options['dsn'] = DSN;
$db_options['mail_table'] = 'mail_queue';
// mail_queue sending options
$mail_options['driver'] = 'smtp';
$mail_options['host'] = 'smtp.gmail.com';
$mail_options['port'] = 25;
$mail_options['localhost'] = $host;
$mail_options['auth'] = true;
$mail_options['user'] = MAILUSER;
$mail_options['pass'] = MAILPASS;
require "Queue.php";
$mail_queue =& new Mail_Queue($db_options,$mail_options);
$from = 'someone#domain.ca';
$to = 'martin#starmedia.ca';
$message = 'This is a test';
$headers = array('From' => $from,
'To' => $to,
'Subject' => 'Someone has sent you an email!');
$mime =& new Mail_mime();
$mime->setTXTBody($message);
$body = $mime->get();
$headers = $mime->headers($headers,true);
print $mail_queue->put($from,$to,$headers,$body);
This produces the error Mail Queue Error: Cannot connect to database . However I checked all of the connection information and it's correct. Also, adding if (PEAR::isError($mail)) die($mail->getMessage()); produces no errors!
OK, I finally have my mail queue file working. Here are the steps I took to get it to function:
1. Enable error messages
To enable error handling, I added this snippet:
function handle_pear_error($e) {
die($e->getMessage() . ' ' . print_r($e->getUserInfo(), true));
}
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'handle_pear_error');
Once I added this, I reloaded the page and I was getting the following error:
Call to undefined function: MDB2_Driver_mysql::_isNewLinkSet()
2. Update MDB2's MySQL driver
I searched that error and found that it's usually a result of either not having an up-to-date MDB2 library or its MySQL driver.
So I updated both and it's working!