Solved

Host Requires SMTP, Host

Posted on 2004-09-22
7
310 Views
Last Modified: 2013-12-13
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
Comment
Question by:snikki
  • 3
7 Comments
 
LVL 27

Accepted Solution

by:
Diablo84 earned 500 total points
ID: 12126221
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
 
LVL 49

Expert Comment

by:Roonaan
ID: 12127411
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
 
LVL 34

Expert Comment

by:gr8gonzo
ID: 12137560
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
 
LVL 27

Expert Comment

by:Diablo84
ID: 12148132
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
 
LVL 27

Expert Comment

by:Diablo84
ID: 12148137
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
delete database record with modal 21 34
Phone Dialer 5 38
uploading multiple image with php 14 20
PHP string issue 5 18
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now