Jump to content

PHP with SMTP


bogdan

Recommended Posts

Hi, I am used Coffee Cup Flash Form Builder in order to make a flash form, which is connected with PHP and XML.
I don't know where should I type to SMTP address, the user name and the password in PHP code. Can anybody help me?
Here's the PHP code
[code]<?php
/****************************************************/
/* CoffeeCup Software Form to Mail program          */
/* (C) 2005 CoffeeCup Software                      */
/****************************************************/
/* - Companion Program For Coffeecup Form Builder - */
/* Visit - http://www.coffeecup.com                */
/****************************************************/
/* Constants  */
/* Version    */ $version = '2.5';
/* Date       */ $date = '1/22/06';
/* Error Level */ error_reporting(E_ALL & ~E_NOTICE);
/* Text File  */ $saveFile = 'form001';

//...... Added UTF-8 support

//Config file must be in the same directory as this file
//and have the same first part of the name. i.e. myform.inc.php
list($formName,$ext) =  split('\.',basename($_SERVER['PHP_SELF']),2);
if (file_exists($formName.".inc.php"))
{
        include($formName.".inc.php");
}

//XML file must be in the same directory as this file
$debug = (isset($_REQUEST['debug'])) ? $_REQUEST['debug'] : $debug;
if ($debug) error_reporting(E_ALL);

//...... Display debugging information
if ($debug)
{
        switch($debug)
        {
                case 'info'    :
                  phpinfo();
                  exit();
                break;

                case 'version'  :
                  err("Current MailForm version: <b>".$version."</b><br>Current PHP version: <b>".phpversion()."</b><br> Current Revision Date: <b>$date</b>");
                break;
        }
}


$date=date("l, F dS, Y \a\\t g:i a");
$server=$_SERVER['SERVER_NAME'];

$msg="Here is the information submitted to $formName from $_SERVER[REMOTE_ADDR] on $date\r\n\r\n------------------------\r\n";

//...... Make sure we keep the variables
$subject        = $_REQUEST['subject'];
$thankyoupage  = $_REQUEST['thankyoupage'];
$xmlFile        = $_REQUEST['xmlfile'];
$unreg          = $_REQUEST['uR'];
$email          = $_REQUEST['eM'];

if (file_exists($xmlFile))
{
        $fd = fopen(basename($xmlFile),'r');
        while(!feof($fd))
        {
                $contents .= fgets($fd,1024);
        }
        fclose($fd);
}
else
{
        err("No &lt;xml&gt; data file found<br>Please upload the data xml file ".$_REQUEST['xmlfile']);
}

$file_info = preg_replace("/\r|\n/"," ",$contents);

//...... Includes the form results in your thank you page
$incresults =  (preg_match('/<form.*?includeresults="true".*?>/',$file_info));

//...... Sends email of form results to the user
$emailusr =  (preg_match('/<form.*?emailuser="true".*?>/',$file_info));

preg_match('/<hidden.*?name="mailto".*?value="(.*?)".*?>/',$file_info,$matches);
$mailto = $matches[1];

preg_match('/<hidden.*?name="thankyoumessage".*?value="(.*?)".*?>/',$file_info,$matches2);
$thanksMsg = unhtmlentities($matches2[1]);


preg_match('/<form.*?bkcolor2="(.*?)".*?>/',$file_info,$matches3);
$backgroundclr = $matches3[1];

preg_match('/<form.*?fontcolor2="(.*?)".*?>/',$file_info,$matches4);
$fontclr = $matches4[1];

preg_match('/<form.*?autoresponse="(.*?)".*?>/',$file_info,$matches5);
$autoresponse = $matches5[1];

if(!$thanksMsg)
{
    $thanksMsg="Thank you for your form submission!";
}

if(!$subject)
{
  $subject="Form Submission";
}


//...... Reversing array elements so they appear in correct form order
$_REQVARS = array_merge($_POST,$_GET);

//...... Delete them from the request array, we won't need
//...... to send these in the actual email.
unset($_REQVARS['thankyoupage']);
unset($_REQVARS['subject']);
unset($_REQVARS['mailto']);
unset($_REQVARS['xmlfile']);
unset($_REQVARS['thankyoumessage']);
unset($_REQVARS['uR']);
unset($_REQVARS['eM']);


$addtoThank.="<span><p align=\"center\">Below is the information you submitted:</br></br></p><p align=\"center\">";
$txtmsg=$formName.'|'.date("Y-m-d H:i:s").'|'.$_SERVER['REMOTE_ADDR'].'|';

$_REQVARS=array_reverse($_REQVARS);

foreach($_REQVARS as $key=>$value)
{
    $new1=str_replace("_"," ",$key);
    $msg .= "$new1: ".stripslashes($value)."\r\n\r\n";
    $addtoThank.="$new1: ".stripslashes($value)."<br/>";
    $txtmsg .= "$new1: ".stripslashes($value)."|";
}

$addtoThank.="</p></span>";
$addtoThank=str_replace("_"," ",$addtoThank);

//...... Write to the text file here
if ($saveFile != '[FILENAME]')
{
        $fd = fopen($saveFile,"a+");
        ccfputcsv($fd, $txtmsg);
        fclose($fd);
}

if($unreg == 'true')
{
$unregMsg="<div align=\"center\"><font size=\"1\" face=\"Arial\">Created with CoffeeCup Form Builder <a href=\"http://www.coffeecup.com/\" target=\"_blank\" title=\"CoffeeCup Form Builder\">Download It Here</a></font></div>";
$msg .= "------------------------\r\n\r\nThis Form was sent to you using CoffeeCup Form Builder.\r\nPlease tell a friend about us: http://www.coffeecup.com/form-builder/\r\n";
}
else
{
$unregMsg = '';
}

$newMsg= $msg . $autoresponse;

//...... Construct a proper mime/UTF-8 for extended ASCII, and internationalization
$headers = "MIME-Version: 1.0\r\n" . "Content-type: text/plain; charset=UTF-8\r\n\r\n";

//...... If they specify "email" in their form, it will set the reply-to field.
if($email)
{
$sentMail = mail($mailto,$subject,$newMsg,"Reply-To: $email\r\nFrom: $email\r\n$headers");

//...... MAIL TO USER
if($emailusr)
{
mail($email,$subject,$newMsg,"Reply-To: $mailto\r\nFrom: $mailto\r\n$headers");
}
}
//...... Send email as regular web server user
else
{
        $sentMail = mail($mailto,$subject,$newMsg,$headers);
}

if (!$sentMail) err("Cannot send email!");

if(!$incresults)
{
        $addtoThank="";
}

if($thankyoupage)
{
  header("Location: $thankyoupage");
}
else
{
        print <<<__EOT__
<html>

<head>
<title>Form Submitted</title>
<style type="text/css">
<!--
body {
    background-color:$backgroundclr;
}
#message {
        width:720px;
    margin:9px auto;
        text-align:center;
    font:bold 14px 'Trebuchet MS',arial,helvetica,sans-serif;
    color:$fontclr;
}
#message span {
    font-weight:normal;
}
//-->
</style>
</head>

<body bgcolor="$background-color">
<center>
<div id="message"><div>$thanksMsg</div>
<br /><br />
$addtoThank
<br /><br />
$unregMsg
</center>
</body>

</html>
__EOT__;

}

function err($string)
{
        global $version;
        echo("<h2 style=\"font:normal 20px 'Trebuchet MS',arial\">$string</h2>");
        echo("<h2 style=\"font:normal 12px 'Trebuchet MX',arial\">Either sendmail or smtp is not properly configured on your system.<br />Please contact your hosting provider to correct this problem.<!-- $version --></h2>");
        exit();
}

function ccfputcsv($handle, $mymsg)
{
  fputs($handle, $mymsg."\n");//stripslashes(substr($str, 0, -1))

  return strlen($mymsg);
}

function unhtmlentities($string)
{
  $trans_tbl = get_html_translation_table(HTML_ENTITIES);
  $trans_tbl = array_flip($trans_tbl);
  return strtr($string, $trans_tbl);
}[/code]

Thank you!
Link to comment
https://forums.phpfreaks.com/topic/36217-php-with-smtp/
Share on other sites

[quote author=bogdan link=topic=124579.msg516379#msg516379 date=1170102880]
Maybe it seems to be OK, but when I test it, it says that the mail can't be sent, and it ask me to check the server. I have a SMTP server that I can use, but I don't know where to add the datas.
[/quote]
It might be PHPs configuration. If you can edit PHP's config (php.ini) then you'll need to edit the following lines
[code][mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25

; For Win32 only.
sendmail_from = y[/code]
Link to comment
https://forums.phpfreaks.com/topic/36217-php-with-smtp/#findComment-172114
Share on other sites

Can you please tell me where can I find this? I am not very familiar with php, I have just this file, an XML file, and the form, which is flash, all of them are integrated. I upload them on server (on Yahoo, there is where I have the hosting), but if I try to use it, it says "Cannot send email!
Either sendmail or smtp is not properly configured on your system.
Please contact your hosting provider to correct this problem."
I can't find where to add these lines that you gave me...  ???
Link to comment
https://forums.phpfreaks.com/topic/36217-php-with-smtp/#findComment-172125
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.