I have been stuck on this for 2 days now. There were a ton of code available, but not one working solution. Below is my code to send the mail once a user requested a service at an auto repair shop. It updates mysql with all of the data and is then suppose to send the mail.
Although it seems that something is happening (apart from the data insertion), it does not send the mail at all. Any help will be appreciated, thanks
<?php
//Get mail smtp from files...
include('smtpconfig.php');
include('smtpclass.php');
//Get connection...
require ("connection.php");
//Form data...
if (!isset($_POST['booking']))
{
$_POST['booking'] = "undefine";
}
$booking = strip_tags($_POST['booking']); //This is my submit button...
$name = strtolower(strip_tags($_POST['name']));
$surname = strtolower(strip_tags($_POST['surname']));
$cell = strip_tags($_POST['cell']);
$worktel = strip_tags($_POST['worktel']);
$email = strip_tags($_POST['email']);
$vehmake = strip_tags($_POST['vehmake']);
$vehmodel = strip_tags($_POST['vehmodel']);
$vehyear = strip_tags($_POST["vehyear"]);
$regnum = strip_tags($_POST['regnum']);
$mileage = strip_tags($_POST['mileage']);
$daterequested = strip_tags(date("Y-m-d"));
$typebook = strip_tags($_POST['typebook']);
$addrepairs = strip_tags($_POST['addrepairs']);
if ($booking) //This is my submit button...
{
//Do validation of entries...
if ($name&&$surname&&$cell&&$worktel&&$email&&$vehmake&&$vehmodel&&$vehyear&&$regnum&&$mileage&&$typebook&&$addrepairs)
{
//Register booking...
//Do database connection...
$querryreglogin = mysql_query("INSERT INTO bookings (id, name, surname, cell, worktel, email, vehmake, vehmodel, vehyear, regnum, mileage, daterequested, typebook, addrepairs) VALUES ('', '$name', '$surname', '$cell', '$worktel', '$email', '$vehmake', '$vehmodel', '$vehyear', '$regnum', '$mileage', '$daterequested', '$typebook', '$addrepairs')");
if($_SERVER["REQUEST_METHOD"] == "POST")
{
$to = "bookings@gmservicecentre.co.za"; //the smtp server
$from = $email;
$subject = "Service Booking Request";
$body = $name ." " . $surname ." wishes to confirm a date for a " . $typebook ." on their " . $vehyear .", " . $vehmake .", " . $vehmodel ."with" . $mileage ." kilometres and " . $regnum .". They also require " . $addrepairs ." additional work to be carried out. The can be contacted on - Cellphone Number " . $cell .", Work Telephone Number " . $worktel ." or on their e-mail address at " . $email;
$SMTPMail = new SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from, $to, $subject, $body);
$SMTPChat = $SMTPMail->SendMail();
}
echo("<script type='text/javascript'>window.alert('Thank you for making a booking with us. Prescilla will confirm your date and time of the booking soon.')</script>");
echo("<a href=\'index.php'>Click Here If You Are Not Re-directed Automatically</a>");
echo("<script type='text/javascript'>location.replace('index.php');</script>"); //I get the message and I get redirected to index.php, no message though...
}
else
echo "<script type='text/javascript'>window.alert('Please complete ALL required fields (marked with red exclamation image).')</script>";
}
?>
smtpconfig file code
<?php
//Server Address
//$SmtpServer="mail.gmservicecentre.co.za";
$SmtpServer="pop3.gmservicecentre.co.za";
$SmtpPort="110"; //default
$SmtpUser="*****";
$SmtpPass="******";
?>
The smtpclass file code
<?php
class SMTPClient
{
function SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from, $to, $subject, $body)
{
$this->SmtpServer = $SmtpServer;
$this->SmtpUser = base64_encode ($SmtpUser);
$this->SmtpPass = base64_encode ($SmtpPass);
$this->from = $from;
$this->to = $to;
$this->subject = $subject;
$this->body = $body;
if ($SmtpPort == "")
{
$this->PortSMTP = 110;
}
else
{
$this->PortSMTP = $SmtpPort;
}
}
function SendMail ()
{
if ($SMTPIN = fsockopen ($this->SmtpServer, $this->PortSMTP))
{
fputs ($SMTPIN, "EHLO ".$HTTP_HOST."\r\n");
$talk["hello"] = fgets ( $SMTPIN, 1024 );
fputs($SMTPIN, "auth login\r\n");
$talk["res"]=fgets($SMTPIN,1024);
fputs($SMTPIN, $this->SmtpUser."\r\n");
$talk["user"]=fgets($SMTPIN,1024);
fputs($SMTPIN, $this->SmtpPass."\r\n");
$talk["pass"]=fgets($SMTPIN,256);
fputs ($SMTPIN, "MAIL FROM: <".$this->from.">\r\n");
$talk["From"] = fgets ( $SMTPIN, 1024 );
fputs ($SMTPIN, "RCPT TO: <".$this->to.">\r\n");
$talk["To"] = fgets ($SMTPIN, 1024);
fputs($SMTPIN, "DATA\r\n");
$talk["data"]=fgets( $SMTPIN,1024 );
fputs($SMTPIN, "To: <".$this->to.">\r\nFrom: <".$this->from.">\r\nSubject:".$this->subject."\r\n\r\n\r\n".$this->body."\r\n.\r\n");
$talk["send"]=fgets($SMTPIN,256);
//CLOSE CONNECTION AND EXIT ...
fputs ($SMTPIN, "QUIT\r\n");
fclose($SMTPIN);
//
}
return $talk;
}
}
?>