I'm trying to send mail with Gmail as server. The email is never sent, and no confirmation or error messages given. Mail, Net_SMTP and Net_Socket pear packages are installed. I set the proxy, and can connect to the internet via cmd. The echo after the "send" never appears, but the one before does, which means the connection status is null. Can anyone see what I'm missing/misunderstanding?
php:
if (isset($_POST['submit'])){
error_reporting(0);
$human = $_POST['human'];
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$to = 'toreceive#gmail.com';
$body = "$message";
$header = array (
'From' => 'tosend#gmail.com',
'Subject' => 'Hello'
);
$smtp = Mail::factory('smtp', array(
'auth' => true,
'host' => 'ssl://smtp.gmail.com',
'port' => '465',
'username' => 'username#gmail.com',
'password' => 'password',
'charset' => 'iso-8859-1'
));
if (connection_status == 0)
echo "<script type='text/javascript'>alert('Before Mail');</script>";
$mail = $smtp->send($to, $header, $body);
echo "<script type='text/javascript'>alert('After Mail');</script>";
if (#PEAR::isError($mail))
echo("<p>" . $mail->getMessage() . "</p>");
else
echo("<p>Message successfully sent!</p>");
}
?>
relevant php.ini:
[mail function]
SMTP = localhost
smtp_port = 25
extension=php_openssl.dll
extension=php_sockets.dll
Related
I have an HTML form for a website hosted on GoDaddy, I'm trying to allow users to use a contact form to contact me via my website, I've created an smtp PHP script however it doesn't seem to work, the script runs and the page reloads but I haven't received any income mail for this test.
<?php
include('Mail.php');
$host = 'localhost';
$username = '******#***********.com';
$password = '*******';
$subject = 'Test';
$from = '******#*********.com';
$to = '******.*******#***.com';
$cc = 'person to CC';
$recipients = $to . ", " . $cc; //
$headers = array ('From' => $from,
'To' => $to,
'Cc' => $cc,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => false,
'username' => $username,
'password' => $password,
'port' => '25'
));
$mail = $smtp->send($recipients, $headers, $body);
if ( PEAR::isError($mail) ) {
echo("<p>Error sending mail:<br/>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message sent.</p>");
}
header("Location:contact-us.html");
?>
I am working on a php website,Using google smtp to send mail,The code is working fine and it is sending mail to inbox, Through google smtp.But now have changed the $username and $password,It is showing me this error,Thankyou in advance
Error! authentication failure [SMTP: Invalid response code received
from server (code: 534, response: 5.7.14 Please log in via your web
browser and 5.7.14 then try again. 5.7.14 Learn more at 5.7.14
https://support.google.com/mail/answer/78754 y11-v6sm11496340pfn.92 - gsmtp)]
<?php
require_once 'Mail.php'; //this loads up PEAR Mail
if (!class_exists('Mail')) { die('Error: The PEAR Mail class does not exist.'); }
$host = 'ssl://smtp.gmail.com';
$username = '****#gmail.com'; //replace this with your new Gmail address
$password = '****'; //replace this with your new Gmail account password
$port = '465';
$from_email = $username;
$from = '"california worker company" <'.$from_email.'>'; //put your name in here, but keep the double quotes
$to = '"california worker company" <softphoton002#gmail.com>'; //put in your name and main email address to send a test to
$subject = 'California Worker Lead for GENERAL CONTRACTORS';
$myname = $_REQUEST['name'];
$myemail = $_REQUEST['email'];
$myphone = $_REQUEST['phone'];
$annualpayroll = $_REQUEST['annualpayroll'];
$numberofemployees = $_REQUEST['numberofemployees'];
$yourbusinesstype = $_REQUEST['yourbusinesstype'];
$healthinsurancecarrier = $_REQUEST['healthinsurancecarrier'];
$payrollservicemethod = $_REQUEST['payrollservicemethod'];
$body = 'Hello Admin <br/> You get a new lead for GENERAL CONTRACTORS.<br/>
Name:'.$myname.'<br/>
Email:'.$myemail.'<br/>
Phone:'.$myphone.'<br/>
Annual Payroll:'.$annualpayroll.'<br/>
Member of Employees:'.$numberofemployees.'<br/>
Business Type:'.$yourbusinesstype.'<br/>
Health Insurance Carrier:'.$healthinsurancecarrier.'<br/>
Payroll Service Method:'.$payrollservicemethod.'<br/>';
$headers = array(
'From' => $from,
'To' => $to,
'Subject' => $subject,
'Reply-To' => $from_email,
'MIME-Version' => 1,
'Content-type' => 'text/html;UTF-8'
);
$params = array(
'host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password
);
$smtp = Mail::factory('smtp', $params);
$mail = $smtp->send($to, $headers, $body);
// To user email
$headerss = array(
'From' => $from,
'To' => $myemail,
'Subject' => $subject,
'Reply-To' => $from_email,
'MIME-Version' => 1,
'Content-type' => 'text/html;UTF-8'
);
$paramss = array(
'host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password
);
$smtps = Mail::factory('smtp', $paramss);
$bodys = 'Hello '.$myname.'<br/>
We received your message for Quote on GENERAL CONTRACTOR. We will reply you in next 24-48 hours.<br/>
Thank you';
$mails = $smtps->send($myemail, $headerss, $bodys);
if (PEAR::isError($mail)) {
echo '<p>Error! '.$mail->getMessage().'</p>';
} else {
header("Location: http://californiaworkercomp.com/general-contractors?success=1");
//echo '<p>Your test message was sent successfully.</p>';
}
?>
I am trying to send mail to gmail account from my web site. It seems that everything is fine at the code level. Can you guys please look into this issue: even if i run this script, mail is not received to gmail Account.
<?php
if(isset($_POST['submit'])){
ini_set('SMTP','localhost');
$msg='Name : '.$_POST['name']."\n"
.'Email : '.$_POST['email']."\n"
.'Message : '.$_POST['message'];
mail("aa#gmail.com","Message from Contact Us",$msg);
}
else{
echo 'cannot send email';
}
?>
I think you will install phpmailer(http://pear.php.net/) and then send through smtp here is example code:
require_once "Mail.php";
$from = '<from#gmail.com>';
$to = '<to#yahoo.com>';
$subject = 'Hi!';
$body = "Hi,\n\nHow are you?";
$headers = array(
'From' => $from,
'To' => $to,
'Subject' => $subject
);
$smtp = Mail::factory('smtp', array(
'host' => 'ssl://smtp.gmail.com',
'port' => '465',
'auth' => true,
'username' => 'your gmail ',
'password' => 'your password'
));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo('<p>' . $mail->getMessage() . '</p>');
} else {
echo('<p>Message successfully sent!</p>');
I need my php script to email me some variables which is parsed to it.
I receive the email properly when any text is passed:
mypage.php?url=hello
But I do not receive the email if an url is passed:
mypage.php?url=http://www.google.com
I searched for hours but didn't found any way to do it.
This is the php script:
<?php
// Pear Mail Library
require_once "Mail.php";
$name = $_POST['name'];
$url = $_POST['url'];
$from = '<noreply#website.com>';
$to = '<me#gmail.com>';
$subject = 'Hi!';
$body = '
Name: '.$name.'
The url is: '.$url.'
';
$headers = array(
'From' => $from,
'To' => $to,
'Subject' => $subject
);
$smtp = Mail::factory('smtp', array(
'host' => 'ssl://smtp.gmail.com',
'port' => '465',
'auth' => true,
'username' => 'mail#gmail.com',
'password' => 'password'
));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo('<p>' . $mail->getMessage() . '</p>');
} else {
echo('<h1>Message successfully sent!</h1>');
}
?>
When an actual url is parsed, I don't recive the email but also no error is shown.
As #Xorifelse said, I used addslashes function and it worked. I got the email properly with the url in it.
Below is the working script:
<?php
// Pear Mail Library
require_once "Mail.php";
$name = $_POST['name'];
$url = $_POST['url'];
$from = '<noreply#website.com>';
$to = '<me#gmail.com>';
$subject = 'Hi!';
$body = '
Name: '.addslashes($name).'
The url is: '.addslashes($url).'
';
$headers = array(
'From' => $from,
'To' => $to,
'Subject' => $subject
);
$smtp = Mail::factory('smtp', array(
'host' => 'ssl://smtp.gmail.com',
'port' => '465',
'auth' => true,
'username' => 'mail#gmail.com',
'password' => 'password'
));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo('<p>' . $mail->getMessage() . '</p>');
} else {
echo('<h1>Message successfully sent!</h1>');
}
?>
Sorry for my English.
I’m trying to sent e-mai via Mail pear packet:
require_once "Mail.php";
$from = '<frommail#gmail.com>';
$to = '<tomail#vacant.lv>';
$subject = 'Hi!';
$body = "Hi,\n\nHow are you?";
$headers = array(
'From' => $from,
'To' => $to,
'Subject' => $subject
);
$smtp = Mail::factory('smtp', array(
'host' => 'ssl://smtp.gmail.com',
'port' => '465',
'auth' => true,
'username' => 'frommail#gmail.com',
'password' => 'pass'
));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo('<p>' . $mail->getMessage() . '</p>');
} else {
echo('<p>Message successfully sent!</p>');
}
//email addresses are changed
But in result I have error:
Failed to connect to ssl://smtp.gmail.com:465 [SMTP: Failed to connect socket: Permission denied (code: -1, response: )]
Openssl is enabled.
Thanks you.
At some stage you might want to send an HTML email, so you would also need to use the Mail/mime package that is provided by PEAR. I've included that as well.
<?php
require_once "Mail.php";
require_once "Mail/mime.php";
$from = "<noreply#example.com>";
$to = "fred#example.com"; // the email address
$host = "smtp.gmail.com";
$port = "587";
// use the first example username if sending from gmail, as full email address
// is required
$username = "fred.flintstone#gmail.com";
$username = "fred";
$password = "secure";
$headers = array ('From' => $from,'To' => $to,'Subject' => $subject);
$mailbody = "<html><body>...</body></html>";
$mime = new Mail_mime();
$mime->setHTMLBody($mailbody);
$body = $mime->get();
$headers = $mime->headers($headers);
$smtp = Mail::factory(
'smtp',array (
'host' => $host,
'auth' => true,
'username' => $username,
'password' => $password,
'port' => $port
)
);
// send email
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo($mail->getMessage());
} else {
echo "<b><Center>Succesfully sent email to</b>$to</center>";
}