I am trying to set up a system where a customer is sent an email containing radio buttons and a submit button, which then directs them to a WordPress page containing PHP, which will then send an email to our support team with the details. I have installed exec_php on wordpress and used PHP scripts modified from those I found on the web, however despite checking everything I can think of, it still does not send the email back, despite SOME of the PHP executing.
The PHP on the wordpress page:
<?php if($_SERVER["REQUEST_METHOD"] == "POST")
{
$to = "example@gmail.com";
$from = "no-reply@oursite.co.uk";
$resolved = $_POST['yesno'];
if ($resolved=='This issue was resolved.')
{$body = $_POST['cust'] . "has responded to an email asking for feedback regarding the closure of case number" . $_POST['casesendid'] . "The person in question responded that they are satisfied with the resolution. Please do not reply to this email.";}
else
{$body= $_POST['cust'] . "has responded to an email asking for feedback regarding the closure of case number" . $_POST['casesendid'] . "The person in question responded that they are not satisfied with the resolution. Please do not reply to this email.";}
$subject = "Automated Feedback Message";
$SMTPMail = new SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from, $to, $subject, $body);
$SMTPChat = $SMTPMail->SendMail();
}
echo $resolved;
?>
The template of the page contains php includes to the two files in the same directory, in “settings.php”:
<?php
//Server Address
$SmtpServer="smtp.hosts.co.uk";
$SmtpPort="25"; //default
$SmtpUser="oursite.co.uk";
$SmtpPass="password";
?>
and in mailclass.php:
<?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 = 25;
}
else
{
$this->PortSMTP = $SmtpPort;
}
}
function SendMail ()
{
if ($SMTPIN = fsockopen ($this->SmtpServer, $this->PortSMTP))
{
fputs ($SMTPIN, "EHLO ".$HTTP_HOST."rn");
$talk["hello"] = fgets ( $SMTPIN, 1024 );
fputs($SMTPIN, "auth loginrn");
$talk["res"]=fgets($SMTPIN,1024);
fputs($SMTPIN, $this->SmtpUser."rn");
$talk["user"]=fgets($SMTPIN,1024);
fputs($SMTPIN, $this->SmtpPass."rn");
$talk["pass"]=fgets($SMTPIN,256);
fputs ($SMTPIN, "MAIL FROM: <".$this->from.">rn");
$talk["From"] = fgets ( $SMTPIN, 1024 );
fputs ($SMTPIN, "RCPT TO: <".$this->to.">rn");
$talk["To"] = fgets ($SMTPIN, 1024);
fputs($SMTPIN, "DATArn");
$talk["data"]=fgets( $SMTPIN,1024 );
fputs($SMTPIN, "To: <".$this->to.">rnFrom: <".$this->from."> nSubject:".$this->subject."rnrnrn".$this->body."rn.rn");
$talk["send"]=fgets($SMTPIN,256);
//CLOSE CONNECTION AND EXIT ...
fputs ($SMTPIN, "QUITrn");
fclose($SMTPIN);
//
}
return $talk;
}
}
?>
All the password and username fields are populated with our actual details, and when redirected to the page, the correct value for $resolved is displayed hinting that the php does execute, however no mail is ever received by the $to address. If anyone has any suggestions please help as this is turning into a nightmare.