[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 333
  • Last Modified:

Host Requires SMTP, Host

Hello,

I'm new to PHP. I am using a HTML to form mail program to create my PHP forms.
( Forms to Go, by Bebosoft)

The form i just created isn't working because my host requires SMTP to send form email. But  the form program doesn't include an option for SMTP mail just "sendmail".
(The host also says they also support "PEAR Mail::Factory method.)

I'm not sure how/where to insert the correct SMTP code into my exisitng form. (which I've pasted below.)


Does anyone out there know the correct code to insert into this form for SMTP mail?

Here is what PEAR Mail::Factory method has:
function procform(&$data)
{
    if(!validate($data))
        return form($data);

    $recipients = $data["to"];
    $headers['From']    = '"My company Corp" <alex@yourdomain.name>';
    $headers['Bcc']      = '"Bcc" <joedoebcc@somedomain.name>';
    $headers['Subject'] = $data["subj"];
    $body = $data["msg"];
    $params['host'] = 'scriptmail.intermedia.net';
    // Create the mail object using the Mail::factory method
    $mail_object =& Mail::factory('smtp', $params);
    if ( $mail_object->send($recipients, $headers, $body) )
        return "Mail was successfully sent";
    else
        return "Cannot send mail!";
}



BELOW IS THE FORM PROCESSOR I CREATED IN BEBOSOFT:
<?PHP
# ----------------------------------------------------
# -----
# -----  Forms To Go v2.5.7 by Bebosoft, Inc.
# -----
# -----  http://www.bebosoft.com/
# -----
# ----------------------------------------------------


#----------
# Validate: String

function check_string($value, $low, $high, $mode, $optional)
{
 if ( (strlen($value) == 0) && ($optional === true) ) {
  return true;
 } elseif ( (strlen($value) >= $low) && ($mode == 1) ) {
  return true;
 } elseif ( (strlen($value) <= $high) && ($mode == 2) ) {
  return true;
 } elseif ( (strlen($value) >= $low) && (strlen($value) <= $high) && ($mode == 3) ) {
  return true;
 } else {
  return false;
 }
}

$FTGcompany = $company;
$FTGname = $name;
$FTGposition = $position;
$FTGindustry = $industry;
$FTGaddress = $address;
$FTGcity = $city;
$FTGstate = $state;
$FTGzip = $zip;
$FTGcountry = $country;
$FTGphone = $phone;
$FTGemail = $email;
$FTGproducts = $products;
$FTGmanufacture = $manufacture;
$FTGhowhear = $howhear;
$FTGcomments = $comments;
$FTGSubmit = $Submit;

# Fields Validations

$validationFailed = false;

if ( (! check_string($FTGcompany, 1, 0, 1, true))) {
 $validationFailed = true;
}

if ( (! check_string($FTGname, 1, 0, 1, false))) {
 $validationFailed = true;
}

if ( (! check_string($FTGposition, 1, 0, 1, true))) {
 $validationFailed = true;
}

if ( (! check_string($FTGaddress, 1, 0, 1, false))) {
 $validationFailed = true;
}

if ( (! check_string($FTGcity, 1, 0, 1, false))) {
 $validationFailed = true;
}

if ( (! check_string($FTGstate, 1, 0, 1, false))) {
 $validationFailed = true;
}

if ( (! check_string($FTGzip, 1, 0, 1, false))) {
 $validationFailed = true;
}

if ( (! check_string($FTGcountry, 1, 0, 1, false))) {
 $validationFailed = true;
}

if ( (! check_string($FTGemail, 1, 0, 1, false))) {
 $validationFailed = true;
}

# Redirect user to the error page

if ($validationFailed == true) {

 header("Location: error.html");
 exit;

}


# Email to Form Owner

$emailTo = '"Mary" <marys@ashbydillon.com>';

$emailSubject = "Online Submission Form" . date('m/d/y') . "";

$emailHeader = "From: $FTGcompany\n"
 . "Reply-To: $FTGcompany\n"
 . "Return-Path: $FTGcompany\n"
 . "X-Sender: $FTGcompany\n"
 . "X-Mailer: PHP\n"
 . "X-Priority: 3\n"
 . "MIME-Version: 1.0\n";

$emailBody = "Content-Type: text/html; charset:\"ISO-8859-1\"\n"
 . "Content-Transfer-Encoding: quoted-printable\n"
 . "\n"
 . "<HTML>\n"
 . "<head>\n"
 . "<title></title>\n"
 . "</head>\n"
 . "<body>\n"
 . "company: $FTGcompany<br />\n"
 . "name: $FTGname<br />\n"
 . "position: $FTGposition<br />\n"
 . "industry: $FTGindustry<br />\n"
 . "address: $FTGaddress<br />\n"
 . "city: $FTGcity<br />\n"
 . "state: $FTGstate<br />\n"
 . "zip: $FTGzip<br />\n"
 . "country: $FTGcountry<br />\n"
 . "phone: $FTGphone<br />\n"
 . "email: $FTGemail<br />\n"
 . "products: $FTGproducts<br />\n"
 . "manufacture: $FTGmanufacture<br />\n"
 . "howhear: $FTGhowhear<br />\n"
 . "comments: $FTGcomments<br />\n"
 . "Submit: $FTGSubmit<br />\n"
 . "</body>\n"
 . "</html>\n"
 . "\n"
 . ""
 . "\n";

mail($emailTo, $emailSubject, $emailBody, $emailHeader);

# Confirmation Email to User

$confEmailTo = $FTGemail;

$confEmailSubject = "Online Submission Form Confirmation";

$confEmailBody = "company: $FTGcompany\n"
 . "name: $FTGname\n"
 . "position: $FTGposition\n"
 . "industry: $FTGindustry\n"
 . "address: $FTGaddress\n"
 . "city: $FTGcity\n"
 . "state: $FTGstate\n"
 . "zip: $FTGzip\n"
 . "country: $FTGcountry\n"
 . "phone: $FTGphone\n"
 . "email: $FTGemail\n"
 . "products: $FTGproducts\n"
 . "manufacture: $FTGmanufacture\n"
 . "howhear: $FTGhowhear\n"
 . "comments: $FTGcomments\n"
 . "Submit: $FTGSubmit\n"
 . "";

$confEmailHeader = "From: marys@ashbydillon.com\n"
 . "Reply-To: marys@ashbydillon.com\n"
 . "Content-type: text/plain; charset=\"ISO-8859-1\"\n"
 . "Content-transfer-encoding: quoted-printable\n";

mail($confEmailTo, $confEmailSubject, $confEmailBody, $confEmailHeader);

# Redirect user to success page

header("Location: thankyou.html");
exit;

# End of PHP script
?>

Thanks!
0
snikki
Asked:
snikki
  • 3
1 Solution
 
Diablo84Commented:
My advice is just use php mailer, it makes this process much easier and allows you to easily specify an smtp host.

http://phpmailer.sourceforge.net/

phpmailer is a class that handles all of the mail processing for you, sending mail is very easy as demonstrated by the example on phpmailers website:

require("class.phpmailer.php");

$mail = new PHPMailer();

$mail->IsSMTP();                                   // send via SMTP
$mail->Host     = "smtp1.site.com;smtp2.site.com"; // SMTP servers
$mail->SMTPAuth = true;     // turn on SMTP authentication
$mail->Username = "jswan";  // SMTP username
$mail->Password = "secret"; // SMTP password

$mail->From     = "from@email.com";
$mail->FromName = "Mailer";
$mail->AddAddress("josh@site.com","Josh Adams");
$mail->AddAddress("ellen@site.com");               // optional name
$mail->AddReplyTo("info@site.com","Information");

$mail->WordWrap = 50;                              // set word wrap
$mail->AddAttachment("/var/tmp/file.tar.gz");      // attachment
$mail->AddAttachment("/tmp/image.jpg", "new.jpg");
$mail->IsHTML(true);                               // send as HTML

$mail->Subject  =  "Here is the subject";
$mail->Body     =  "This is the <b>HTML body</b>";
$mail->AltBody  =  "This is the text-only body";

if(!$mail->Send())
{
   echo "Message was not sent <p>";
   echo "Mailer Error: " . $mail->ErrorInfo;
   exit;
}

echo "Message has been sent";
0
 
RoonaanCommented:
probably you have to use the

ini_set("SMTP", "somesmtpserver");
ini_set("sendmail_from", "youremail@yourhost.com");

before mailing. (Note you have to change the values to correct one :-) )

I hope this helps.

-r-
0
 
gr8gonzoConsultantCommented:
I also highly recommend using PHP Mailer - it's an excellent class and I use it in any script that I write that deals with mail.

- J
0
 
Diablo84Commented:
Heres the basics of what you need to do to get phpmailer working.

In the download for phpmailer there is a file called class.phpmailer.php you need to copy this file and put it in the same directory as the form and the script (that you are about to make).

Point the form (ie. in the action) to a file called process.php (or something similar)

Process.php will contain the following:

<?php
//process.php

/* This following section is optional, it checks that the form has been submitted
from your html form page (your submit buton must be called "submit"). If the form hasnt been submitted
then it will redirect to your form page. Change form.html to the name of your form page */

if (!isset($_POST['submit'])) {
 header("location: form.html");
 exit;
}

require("class.phpmailer.php"); //this line includes the phpmailer class which you will use to process the mail

$mail = new PHPMailer();

//these next few lines are used to set up the smpt connection
$mail->IsSMTP();                                   // send via SMTP
$mail->Host     = "smtp1.site.com;smtp2.site.com"; // SMTP servers

//you only need the next 3 lines if your smtp host requires authentication
$mail->SMTPAuth = true;     // turn on SMTP authentication
$mail->Username = "jswan";  // SMTP username
$mail->Password = "secret"; // SMTP password

//to and from
$mail->From = "from_address@yourdomain.com";
$mail->FromName = "Your Name";
$mail->AddAddress("to_address@theirdomain.com","Their Name");

//mail subject
$mail->Subject = "email subject";

//this is the main body of the email where you need to add your content
$mail->Body = "The email body";

/*
you can make the email body multi line like this

$mail->Body = "
Your body contents here, you can includ variables to\n
like this $variable as you would normally
";
*/

$mail->WordWrap = 70;

if(!$mail->Send()) {
 echo "Message was not sent";
 echo "Mailer Error: " . $mail->ErrorInfo;
}
else {
 echo "Message has been sent";
}
?>

You will have to integrate your processing code with the above code so that the script is fully functional for you but this should give you the general idea of how to use the class and combine it with your form and script.

Good Luck.
0
 
Diablo84Commented:
Incidently if needed take a look at the online tutorial which explains some of the features of the class and how to use it http://phpmailer.sourceforge.net/tutorial.html
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now