I developed a site with PHPMailer and used gmail smtp to send emails from my local machine.
My code:
`require_once $_SERVER['DOCUMENT_ROOT'] . '/lib/classes/system.class.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/lib/helpers/send_email.helper.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/modules/settings/classes/settings.class.php';
$sClass = new System();
$settingClass = new Settings();
$template = file_get_contents('../html/frontend/email_contact_form.html');
$site_email = $settingClass->get_setting_value('email_from_address');
$template_data['name'] = $_POST['name'];
$template_data['phone'] = $_POST['phone'];
$template_data['email'] = $_POST['email'];
$template_data['message'] = $_POST['message'];
$template = $sClass->merge_data($template, $template_data);
$result = send_email($_POST['email'], $_POST['name'], $_POST['email'], $_POST['name'], $site_email, 'Ruth Rudin', $_POST['subject'], $template);
echo '<p>Your message has been sent.</p>`
On the live server, I do not use gmail smtp.
My client keeps getting emails from root#localhost.
Could these be emails I tested and got stuck in the queue?
If so, where can I see this queue and delete these emails?
Very confused here.
Thank you
Related
This is the Code , its working on local host
but not working on live server
isSMTP(); i already remove it on live server but still dosent work
require 'phpmalier/PHPMailerAutoload.php';
$email = new PHPMailer;
//$email->isSMTP();
$email->Host='smtp.gmail.com';
$email->Port=587;
$email->SMTPAuth=true;
$email->SMTPSecure='tls';
$email->Username='exmapile#gmail.com';
$email->Password='*******';
$email->SetFrom('exmpile#gmail.com');
$email->AddAddress('exmpile#gmail.com');
$email->isHtml(True);
$email->Subject= $mail . 'Contact Form';
$email->Body= $user .'<br>'. $phone . '<br>' . $msg;
I am getting Gateway timeout error when using swiftmailer on hosted server. But on my PC localhost, its works fine.
When I informed to my hosting, they said they have enabled the outbound connection to port no 465.
Script I have used.
$name = $_REQUEST['name'];
$email = $_REQUEST['email'];
$message = $_REQUEST['message'];
require_once 'mailer/lib/swift_required.php';
// Create the Transport
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl')
->setUsername('myemail#gmail.com')
->setPassword('myapppassword')
;
// Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance()
->setSubject('New Message From ' . $name)
->setFrom(array($email => '$name'))
->setReplyTo($email)
->setTo(array('myemail#gmail.com' => 'My Name'))
->setBody($message)
->addPart('Message: <b>'. $message .'</b>', 'text/html')
;
$result = $mailer->send($message);
if(!$result) {
echo $msg = 'Oops. Something went wrong. Please try again later.';
} else {
echo $msg = 'Thank you. Your query has been submitted. We will contact you back through the provided email address.';
}
Above code used only for hiding headers. But headers are used in order to direct.
I was working on a project for a client, it selects an email from a database and then sends an email to that address. Everything worked fine on my VPS server running CentOS 6, but when migrating to their shared hosting the program will no longer send the email. It will select the correct addresses, but no message will be sent, I've already installed Pear Mail and Mail_mime. Any thoughts?
This code connects to the server:
$headers['From'] = 'mail#openmailbox.org';
$headers['To'] = 'mail#openmailbox.org';
$headers['Subject'] = $asunto;
$params['host'] = 'smtp.openmailbox.org';
$params['port'] = '25';
$params['auth'] = 'PLAIN';
$params['username'] = 'mail#openmailbox.org';
$params['password'] = 'password';
This code selects the recipients:
$result = mysql_query($query);
while($row = mysql_fetch_array($result))
{
$addresses[] = $row['email'];
}
$recipients = implode(", ", $addresses);
Hope you can help me!
Here, this is my email sending code
$mail =& Mail::factory('smtp', $params);
$mime = new Mail_mime($crlf);
$mime->setTXTBody($text);
$mime->setHTMLBody($html);
$body = $mime->get();
$headers = $mime->headers($headers);
$mail->send($recipients, $headers, $body);
Well, I solved it. I replaced pear mail with the default mail function.
im a php beginner, and I am building a website, and website is supposed to let people send me email. the thing is i never knew anything about sending emails through php. I looked it up online and tried using the codes i found. The thing is my program says it sent the email but i never happen to get the email. I thought maybe it is because I am using apache server to test my php, and maybe it is gona work when I upload it to a real server??(yes this was a question)
Just in case, this is my code, and it is the all php code in my website, also form works fine, there is nothing wrong with it.
<?php
if (isset($_POST['name'])) {
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = "From: " . $_POST['name'] . ", " . $_POST['email'] . "\n Message: " . $_POST['message'];
try {
mail("serdarufuk95#gmail.com", $subject, $message, " ");
unset($_POST['name']);
header("Location: success.php");
}
catch (PDOException $e)
{
include 'index.html';
exit();
}
exit();
}
include 'contact2.php';
?>
is there a problem with the code? or do i have to call something from a library or anything or am i missing a code! HELP ME MAKE THIS WORK! when i execute it, it takes me to success.php, so i assumed nothing is wrong with my code, but you guys know better!
It might not work after uploading to a real server if the server's mail configuration has not been set yet. So I suggest you to use a better and simpler version in order to send mails through PHP: PHPMailer
require_once("class.phpmailer.php");
$mail = new PHPMailer();
$mail->AddAddress("mail#domain.com","Display name");
$mail->Subject= "Mail subject";
$mail->Body= "Mail content";
$mail->IsSMTP();
$mail->Host = "mail.domain.com";
$mail->SMTPAuth = true;
$mail->Username = "formmail#domain.com";
$mail->Password = "123456";
$mail->IsHTML(true); //true if you want to send html content. false for plain text message
$mail->From = $_POST['Email'];
$mail->FromName = $_POST['Name'];
$mail->Send();
You may download the class clicking here
how i can access my gmail account through my php code? I need to get the subject and the from address to from my gmail account.And then i need to mark the accessed as read on gmail
Should i use gmail pop3 clint?is that any framework that i can use for accessing gmail pop3
server.
I would just use the PHP imap functions and do something like this:
<?php
$mailbox = imap_open("{imap.googlemail.com:993/ssl}INBOX", "USERNAME#googlemail.com", "PASSWORD");
$mail = imap_search($mailbox, "ALL");
$mail_headers = imap_headerinfo($mailbox, $mail[0]);
$subject = $mail_headers->subject;
$from = $mail_headers->fromaddress;
imap_setflag_full($mailbox, $mail[0], "\\Seen \\Flagged");
imap_close($mailbox);
?>
This connects to imap.googlemail.com (googlemail's imap server), sets $subject to the subject of the first message and $from to the from address of the first message. Then, it marks this message as read. (It's untested, but it should work :S)
This works for me.
<?php
$yourEmail = "you#gmail.com";
$yourEmailPassword = "your password";
$mailbox = imap_open("{imap.gmail.com:993/ssl}INBOX", $yourEmail, $yourEmailPassword);
$mail = imap_search($mailbox, "ALL");
$mail_headers = imap_headerinfo($mailbox, $mail[0]);
$subject = $mail_headers->subject;
$from = $mail_headers->fromaddress;
imap_setflag_full($mailbox, $mail[0], "\\Seen \\Flagged");
imap_close($mailbox);
?>
You can use IMAP from PHP.
<?php
$mbox = imap_open("{imap.example.org:143}", "username", "password")
or die("can't connect: " . imap_last_error());
$status = imap_setflag_full($mbox, "2,5", "\\Seen \\Flagged");
echo gettype($status) . "\n";
echo $status . "\n";
imap_close($mbox);
?>
Another nice IMAP example is available at http://davidwalsh.name/gmail-php-imap
Zend Framework has the Zend_Mail API for reading mail as well. It makes it easy to switch protocols if need be (POP3, IMAP, Mbox, and Maildir). Only the IMAP and Maildir storage classes support setting flags at this time.
http://framework.zend.com/manual/en/zend.mail.read.html
Read messages example from the Zend Framework docs:
$mail = new Zend_Mail_Storage_Pop3(array('host' => 'localhost',
'user' => 'test',
'password' => 'test'));
echo $mail->countMessages() . " messages found\n";
foreach ($mail as $message) {
echo "Mail from '{$message->from}': {$message->subject}\n";
}