Hostbuddy SMTP mail test, having troubles, could not connect to SMTP host - php

I am very new to php and im trying to set up a postmaster, I am using Hostbuddy for my hosting site and downloaded their smtp information for my server.
I got these files from them automatically uploaded to my server for testing the smtp:
class.phpmailer.php
class.smtp.php
index.php
web.config
I think i am entering the correct information for the test. but i keep getting a callback that says, "Could not connect to smtp server".
Here is the index.php so you guys can see what is going on.
<Center><h2>PHP Test Email Script</h2></center>
<?php
// display form if user has not clicked submit
if (!isset($_POST["submit"])) {
?>
<form method="post" action="<?php echo $_SERVER["PHP_SELF"];?>" target="_blank">
<Table align = center>
<tr><td>From Email: <td><input type="text" name="uname"> i.e yourname#yourdomain.com</tr>
<tr><td>Email Password: <td><input type="password" name="pass"></tr>
<tr><td>Host: <td><input type="text" name="host"> i.e Mail.YourDomain.com</tr>
<tr><td>To:<td> <input type="text" name="to"></tr>
<tr><td colspan =2 align = center><input type="submit" name="submit" value="Send Email"></tr>
</table>
</form>
<?php
}
else { // the user has submitted the form
include("class.phpmailer.php"); //you have to upload class files "class.phpmailer.php" and "class.smtp.php"
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Host = $_POST["host"];
$mail->Username = $_POST["uname"];
$mail->Password = $_POST["pass"];
$mail->From = $_POST["uname"];
$mail->FromName = "demouser";
$mail->AddAddress($_POST["to"],"test");
$mail->Subject = "This is the subject";
$mail->Body = "This is a sample message using SMTP authentication";
$mail->WordWrap = 50;
$mail->IsHTML(true);
$str1= "gmail.com";
$str2=strtolower($_POST["uname"]);
If(strstr($str2,$str1))
{
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
echo "<br><br> * Please double check the user name and password to confirm that both of them are correct. <br><br>";
echo "* If you are the first time to use gmail smtp to send email, please refer to this link :http://www.smarterasp.net/support/kb/a1546/send-email-from-gmail-with-smtp-authentication-but-got-5_5_1-authentication-required-error.aspx?KBSearchID=137388";
}
else {
echo "Message has been sent";
}
}
else{
$mail->Port = 25;
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
echo "<br><BR>* Please double check the user name and password to confirm that both of them are correct. <br>";
}
else {
echo "Message has been sent";
}
}
}
?>
Any info would be great, thanks in advance!

You need to add the true smtp gmail so you can add :
smtp-relay.gmail.com smtp.gmail.com aspmx.l.google.com
Setting requirement
Options : port 25, 465 ou 587
Protocoles SSL/TLS (Secure Socket Layer/Transport Layer Security)
Port 465 (SSL require).
Port 587 (TLS require).
Adresses dynamic IP allowed.
Port 25.
TLS no require.
Adresses dynamic IP allowed.

Looks like i had it set up correctly, it just took a few hours for hostbuddy to get the smtp server set up. Works great now :) thanks for the suggestions!

Related

delete query to send a mail depending on field value

I have a delete query below from a php page where the user types in an extension number and the entry is deleted from the database.
Name,Email,Extension,Phone,Department the whole line is deleted by entering the extension number of the database member.
Now I have phpmailer installed and working for this, it is sending a mail to IT#sadsa.com but I am trying to make it also send the mail to another address before the member is deleted from the database depending on the department they are in.
Eg. if they are in Sales department then the email must be sent to sales#sadsa.com and IT#sada.com, if they are in the Admin Department then the mail must be sent to Admin#sadsa.com and IT#asdas.com.
My current code below :
delete.php (the php page where the user enters the extension number to delete)
<?php
require ("database.php");
session_start();
if (!isset($_SESSION['CheckLogin'])) { header("Location: login.php"); }
$this_user_ext =$_REQUEST['extension'];
// sending query
mysql_query("DELETE FROM users WHERE extension = '$this_user_ext'")
or die(mysql_error());
if($_POST['action']) {
include('maildelete.php');
$extension=$_POST['extension'];
header("Location: index.php");
}
?>
<center><form action="" method="post">
Enter 4 Digit Extension Number :<br><input type="text" name="extension"><br><input type="submit" name="action" value="Delete!">
<br> <br>
<h3>
Main Menu
</h3>
</form>
</center>
maildelete.php (this is the script that sends the mail to IT#sad.com)
<?php
$extension = $_POST['extension'];
require 'PHPMailer-master/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "mail.titan-networks.co.za"; // SMTP server // enables SMTP debug information
$mail->SMTPAutoTLS = false;
$mail->SMTPSecure = false;
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Host = "mail.titan-networks.co.za"; // sets the SMTP server
$mail->Port = 587; // set the SMTP port for the GMAIL server
$mail->Username = "jurgen#titan-networks.co.za"; // SMTP account username
$mail->Password = "****"; // SMTP account password
$mail->From = "no-reply#alpinemotors.co.za";
$mail->FromName = "Extension List";
$mail->AddAddress('jurgen#titan-networks.co.za', "");
$mail->isHTML(true);
$mail->Subject = 'Extension Deleted';
$mail->Body = "Extension Number " . $extension . " was removed from the Extension List";
if(!$mail->Send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
echo 'Email Sent Successfully!';
?>

PHP mail function won't send mail to the desired email_id

I have following piece of code. It returns message "send successfully " but we won't receive email at given gmail, Is this code right or have I missed something?
<?php
require("mailer/PHPMailerAutoload.php");
require("mailer/class.smtp.php");
require("mailer/class.phpmailer.php");
$name=$_POST['Your_Name'];
$email=$_POST['Your_Email'];
$message=$_POST['Your_Msg'];
echo $name ;
$mail = new PHPMailer();
// set mailer to use SMTP
//$mail->IsSMTP();
// As this email.php script lives on the same server as our email server
// we are setting the HOST to localhost
$mail->Host = "smtp.gmail.com"; // specify main and backup server
$mail->Port = "465";
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "mandarpatil0003#gmail.com"; // SMTP username
$mail->Password = "Con#Soumitra1"; // SMTP password
// $email is the user's email address the specified
// on our contact us page. We set this variable at
// the top of this page with:
// $email = $_REQUEST['email'] ;
$mail->From = $email;
// below we want to set the email address we will be sending our email to.
$mail->AddAddress("mandarpatil0003#gmail.com", "Mandar");
// set word wrap to 50 characters
$mail->WordWrap = 50;
// set email format to HTML
$mail->IsHTML(true);
$mail->Subject = "You have received feedback from your website!";
// $message is the user's message they typed in
// on our contact us page. We set this variable at
// the top of this page with:
// $message = $_REQUEST['message'] ;
$mail->Body = $message;
$mail->AltBody ="Name : {$name}\n\nEmail : {$email}\n\nMessage : {$message}";
if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
else
{
echo "Thank you for contacting us. We will be in touch with you very soon.";
}
?>
Does this code have any problems or do I have to try a different approach?
<?php
include 'library.php'; // include the library file
include "classes/class.phpmailer.php"; // include the class name
include "classes/class.smtp.php";
if(isset($_POST["send"])){
$email = $_POST["email"];
$mail = new PHPMailer; // call the class
$mail->IsSMTP();
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->SMTPSecure = "ssl";
$mail->Host = "smtp.gmail.com"; //Hostname of the mail server
$mail->Port = 465; //Port of the SMTP like to be 25, 80, 465 or 587
$mail->SMTPDebug = 1;
//$mail->SMTPAuth = false; //Whether to use SMTP authentication
$mail->Username = "****#gmail.com"; //Username for SMTP authentication any valid email created in your domain
$mail->Password = "****"; //Password for SMTP authentication
$mail->AddReplyTo("****#gmail.com", "Reply name"); //reply-to address
$mail->SetFrom("****#gmail.com", "Your Name"); //From address of the mail
// put your while loop here like below,
$mail->Subject = "Your SMTP Mail"; //Subject od your mail
$mail->AddAddress($email, "Asif18"); //To address who will receive this email
$mail->MsgHTML("<b>Hi, your first SMTP mail has been received."); //Put your body of the message you can place html code here
//Attach a file here if any or comment this line,
$send = $mail->Send(); //Send the mails
if($send){
echo '<center><h3 style="color:#009933;">Mail sent successfully</h3></center>';
}
else{
echo '<center><h3 style="color:#FF3300;">Mail error: </h3></center>'.$mail->ErrorInfo;
}
}
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Send mails using SMTP and PHP in PHP Mailer using our own server or gmail server by Asif18</title>
<meta name="keywords" content="send mails using smpt in php, php mailer for send emails in smtp, use gmail for smtp in php, gmail smtp server name"/>
<meta name="description" content="Send mails using SMTP and PHP in PHP Mailer using our own server or gmail server"/>
<style>
.as_wrapper{
font-family:Arial;
color:#333;
font-size:14px;
}
.mytable{
padding:20px;
border:2px dashed #17A3F7;
width:100%;
}
</style>
<body>
<div class="as_wrapper">
<h1>Send mails using SMTP and PHP in PHP Mailer using our own server or gmail server</h1>
<form action="" method="post">
<table class="mytable">
<tr>
<td><input type="email" placeholder="Email" name="email" /></td>
</tr>
<tr>
<td><input type="submit" name="send" value="Send via SMTP" /></td>
</tr>
</table>
</form>
</div>
</body>
</html>

My script can't send the emails properly with postfix installed [duplicate]

This question already has answers here:
donĀ“t recognize variable of php
(2 answers)
Closed 7 years ago.
Hello i made this script:
index.php:
<table width="400" border="0" align="center" cellpadding="3" cellspacing="1"><tr><td><strong>Whitelist Request </strong></td></tr></table><table width="400" border="0" align="center" cellpadding="0" cellspacing="1"><tr><td><form name="form1" method="post" action="send_whitelist.php"><table width="100%" border="0" cellspacing="1" cellpadding="3"><tr><td width="16%">Username</td><td width="2%">:</td><td width="82%"><input name="username" type="text" id="username" size="50"></td></tr><tr><td>Paysafe</td><td>:</td><td><input name="paysafe" type="text" id="paysafe" size="50"></td></td><tr></tr><td>Name</td><td>:</td><td><input name="name" type="text" id="name" size="50"></td></tr><tr><td>Email</td><td>:</td><td><input name="customer_mail" type="text" id="customer_mail" size="50"></td></tr><tr><td> </td><td> </td><td><input type="submit" name="Submit" value="Submit"> <input type="reset" name="Submit2" value="Reset"></td></tr></table></form></td></tr></table>
Email Sender:
<?php
// Contact subject
$subject ="Minecraft Server Whitelist Request";
// Details
$message="Name: $name \n Username: $username \n Paysafe: $paysafe ";
// Mail of sender
$mail_from="$customer_mail";
// From
$header="from: $name <$mail_from>";
// Enter your email address
$to ='n************#gmail.com';
$send_contact=mail($to,$subject,$message,$header);
// Check, if message sent to your email
// display message "We've recived your information"
if($send_contact){
echo "I have received your whitelist request. Please wait.";
}
else {
echo "ERROR";
}
?>
The contents of the textboxes doesen't appear in the mail.
Any ideas?
I normally use PHPMailer to send emails with php. Here's and example to send an email via gmail using an html file as body and attaching an image:
<?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 = 'smtp.gmail.com';
// 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 = "username#gmail.com";
//Password to use for SMTP authentication
$mail->Password = "yourpassword";
//Set who the message is to be sent from
$mail->setFrom('from#example.com', 'First Last');
//Set an alternative reply-to address
$mail->addReplyTo('replyto#example.com', 'First Last');
//Set who the message is to be sent to
$mail->addAddress('whoto#example.com', 'John Doe');
//Set the subject line
$mail->Subject = 'PHPMailer GMail SMTP test';
//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__));
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
$mail->addAttachment('images/phpmailer_mini.png');
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
TIPS:
1 - Check other PHPMailer examples.
2 - PHPMailer Troubleshooting.
3 - Set SMTPDebug = 2 or higher, to see what the remote SMTP server says.
4 - You may have to enable less secure apps on you gmail account.

PHPMailer With Shared Hosting (SMTP Transport)

I have looked and looked for an answer to this and cannot find anything so If this already has an answer please let me know.
I am using PHPMailer and using SMTP to send emails with files attached.
Here is my Code:
<?php
/**
* SMTP Server Using Yahoo To Upload Files And Submit, Port 465 Using SSL
*/
require_once('PHPMailer/PHPMailerAutoload.php');
define('GUSER', '****#yahoo.com'); // Yahoo username
define('GPWD', '*****'); // Yahoo password
$msg = '';
if (array_key_exists('userfile', $_FILES)) {
// First handle the upload
// Don't trust provided filename - same goes for MIME types
// See http://php.net/manual/en/features.file-upload.php#114004 for more thorough upload validation
$uploadfile = tempnam(sys_get_temp_dir(), sha1($_FILES['userfile']['name']));
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
// Upload handled successfully
// Now create a message
// This should be somewhere in your include_path
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 4; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl';
$mail->Host = 'smtp.mail.yahoo.com';
$mail->Port = 465;
$mail->Username = GUSER;
$mail->Password = GPWD;
$mail->setFrom('****#yahoo.com', 'Sent File');
$mail->addAddress('****#****.com');
$mail->Subject = 'Test File';
$mail->msgHTML("My message body");
// Attach the uploaded file
$mail->addAttachment($uploadfile, $_FILES['userfile']['name']);
if (!$mail->send()) {
$msg = "Mailer Error: " . $mail->ErrorInfo;
} else {
$msg = "Message sent!";
}
} else {
$msg = 'Failed to move file to ' . $uploadfile;
}
}
?>
<?php if (empty($msg)) { ?>
<form method="post" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="100000"> Send this file: <input name="userfile" type="file">
<input type="submit" value="Send File">
</form>
<?php } else {
echo $msg;
} ?>
When I Use This on my local lamp server it works perfectly, However when I use it on my Yahoo Hosting Server, I get this error: SMTP ERROR: Failed to connect to server: Permission denied (13)
Looking into what that error represents, It sounds like the problem and solution has to do with the
httpd_can_sendmail
&
httpd_can_network_connect
Settings. It looks like they need to be activated. Source: http://gistpages.com/2013/09/14/phpmailer_smtp_error_failed_to_connect_to_server_permission_denied_13_fix
My problem is that with Yahoo, I cannot access a terminal to change these settings. Does anyone know of any other way to change these settings without having access to a linux terminal of the hosting server?
Thanks
P.S I would not recommend using yahoo as a website hosting provider EVER to anyone!

How to get user mails in my free gmail inbox through contact us form on my website

How to get user mails in my free gmail inbox through contact us form on my website. I do not use email with my website name . i use free gmail. I tried many script but the all need email account on domain.
Does this question have something to do with This One?
Well, so you have a form on your site, your users fill it up and you need an email with that data, right?
Simple example:
<form action="sendMail.php" method="post">
Name: <input type="text" name="name" id="name" /><br />
Email: <input type="text" name="email" id="email" /><br />
Text: <textarea name="text"></textarea><br />
<input type="submit" value="Send" />
</form>
then, the php page wich send the mail:
//php sendThis.php page
<?php
require("class.phpmailer.php");
$name = $_POST['name'];
$email = $_POST['email'];
$text = $name . ', ' . $email . ' has filled the form with the text:<br />' . $_POST['text'];
$from = 'your.email#gmail.com';
$to = 'your.email#gmail.com';
$gmailPass = 'your gmail password';
$mail = new PHPMailer();
$mail->IsSMTP();
// enable SMTP authentication
$mail->SMTPAuth = true;
// sets the prefix to the server
$mail->SMTPSecure = "ssl";
// sets GMAIL as the SMTP server
$mail->Host = 'smtp.gmail.com';
// set the SMTP port
$mail->Port = '465';
// GMAIL username
$mail->Username = $from;
// GMAIL password
$mail->Password = $gmailPass;
$mail->From = $from;
$mail->FromName = $from;
$mail->AddReplyTo($from, $from);
$mail->Subject = 'This is a test!';
$mail->Body = $text;
$mail->MsgHTML($text);
$mail->IsHTML(true);
$mail->AddAddress($to, $to);
if(!$mail->Send()){
echo $mail->ErrorInfo;
}else{
echo 'sent!';
$mail->ClearAddresses();
$mail->ClearAttachments();
}
?>
EDIT: just tested and works fine. Make sure that the 3 files (class.phpmailer.php, class.pop3.php and class.smtp.php) are in the correct include path
Basically, it involves the PHP mail() function:
<?php
mail(yourGmailAddress, object, message);
?>
As you have already observed, this solution works only if the webserver operates a mail server. This mail server may forbid unknown users. So you need to have an email account on that web/mail server (I believe this is the case). The second step then is to forward mail from your website address to you gmail account. I am 90% certain that it is possible from your gmail configuration. It may also be possible from your website mail configuration. But don't configure both!
Try enabling openssl.
Uncomment the line:
extension=php_openssl.dll
in your php.ini file.
You can also put your email address into "action" attribute of the form element. But that's very unreliable. Like this:
<form method='post' action='mailto:your#email.com?Subject=Hello'>
...
</form>
Users must have email client installed and configured for this to work properly. There are some other drawbacks. You have to do some research to find whether this method is for you or not.
http://www.google.com/search?client=opera&rls=en&q=form+action+mailto&sourceid=opera&ie=utf-8&oe=utf-8

Categories