Jump to content

email form


bigrossco

Recommended Posts

I am wanting the code below to be emailed to a specified email address (was told to check the php help forum for a server-side script?)

 

Any help will be most greatfull

 

R

 

<form>
Name:<br>
<input type="text" name="name"
value="Name" size="20">
<br>
Contact Number:<br>
<input type="text" name="number"
value="Phone Number" size="20">
<br>
Email Address:<br>
<input type="text" name="mail"
value="Email Address" size="20">
<br>

<script language="javascript">
var disable_empty_list = true;
</script>
<script language="javascript" src="chainedselects.js"></script>
<script language="javascript" src="content_link.js"></script>

<script language="javascript">
function openLink(url) {
  if (url != "") {
    location.href = url;
  }
  else {
    alert("Please select a car make / model");
  }
}
</script>
</head>

<body onload="initListGroup('links', document.forms[0].category, document.forms[0].site);">

<table align="left" cellpadding="0" cellspacing="0" border="0" width="90%"><tr><td>


<form>
Make:
<br> 
<select name="category" style="width:180px" name="make"></select>
<br>
Model: 
<br>
<select name="site" style="width:180px" name="model"></select>
</form>
</td></tr></table>
<br><br><br><br><br><br><br><br>
Additional Requirments:<br>
<textarea rows="10" cols="30"> </textarea>
<br><br><br>
<input type="submit" value="Send">

Link to comment
https://forums.phpfreaks.com/topic/39161-email-form/
Share on other sites

Heres an smtp mail script i created

 

<?php 

// getmxrr() - fix for windows users 
if(strtoupper(substr(PHP_OS, 0, 3)) == 'WIN'){ 
    function getmxrr($hostname, &$mxhosts){ 
        $mxhosts = array(); 
        exec('nslookup -type=mx '.$hostname, $result_arr); 
        foreach($result_arr as $line){ 
            if(preg_match("/.*mail exchanger = (.*)/", $line, $matches)) $mxhosts[] = $matches[1]; 
        } 
        return (count($mxhosts) > 0); 
    } 
} 
  
// usleep() - fix for >= php5 windows users 
function msleep($usecs){ 
    $temp = gettimeofday(); 
    $start = (int)$temp["usec"]; 
    while(true){ 
        $temp = gettimeofday(); 
        $stop = (int)$temp["usec"]; 
        if(($stop-$start) >= $usecs) break; 
    } 
} 
  
  
function smtp_mail($to, $subject, $message, $from, $header = false, $timeout = 30){ 
  
    $exp_to = explode("@", $to); 
    getmxrr($exp_to[1], $mxhost); 
    $iparr = array(); 
  
    foreach($mxhost as $hostname){ 
        $iphost = gethostbyname($hostname); 
        if($hostname != $iphost && $hostname != $exp_to[1]) $iparr[] = $iphost; 
    } 
  
    if(count($iparr) > 0){ 
  
        $vphp = (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN' && version_compare(phpversion(), "5.0.0", ">=")) ? true : false; 
  
        $ret = array(false, "Can not contact MX host !"); 
        foreach($iparr as $ipaddr){ 
  
            if($connect = @fsockopen($ipaddr, 25, $err_num, $err_msg, $timeout)){ 
  
                $set = true; 
  
                $rcv0 = fgets($connect, 1024); 
                if(substr($rcv0, 0, 3) != "220"){ 
                    fclose($connect); 
                    $ret = array(false, "Response 0 error: ".$rcv0); 
                    $set = false; 
                } 
                 
                if($set){ 
                    $exp_from = explode("@", $from); 
                    fputs($connect, "HELO ".$exp_from[1]."\r\n"); 
                    $rcv1 = fgets($connect, 1024); 
                    if(substr($rcv1, 0, 3) != "250"){ 
                        fclose($connect); 
                        $ret = array(false, "Response 1 error: ".$rcv1); 
                        $set = false; 
                    } 
                } 
                 
                if($set){ 
                    fputs($connect, "MAIL FROM:<".$from.">\r\n"); 
                    $rcv2 = fgets($connect, 1024); 
                    if(substr($rcv2, 0, 3) != "250"){ 
                        fclose($connect); 
                        $ret = array(false, "Response 2 error: ".$rcv2); 
                        $set = false; 
                    } 
                } 
  
                if($set){ 
                    fputs($connect, "RCPT TO:<".$to.">\r\n"); 
                    $rcv3 = fgets($connect, 1024); 
                    if(substr($rcv3, 0, 3) != "250"){ 
                        fclose($connect); 
                        $ret = array(false, "Response 3 error: ".$rcv3); 
                        $set = false; 
                    } 
                } 
                 
                if($set){ 
                    fputs($connect, "DATA\r\n"); 
                    $rcv4 = fgets($connect, 1024); 
                    if(substr($rcv4, 0, 3) != "354"){ 
                        fclose($connect); 
                        $ret = array(false, "Response 4 error: ".$rcv4); 
                        $set = false; 
                    } 
                } 
                 
                if($set){ 
                    if(!$header){ 
                        $header = "From: \"".$exp_from[0]."\" <".$from.">\r\n". 
                            "To: \"".$exp_to[0]."\" <".$to.">\r\n". 
                            "Date: ".date("r")."\r\n". 
                            "Subject: ".$subject."\r\n"; 
                    } 
  
                    $rep = array(".\r\n", ".\n", ".\r"); 
                    fputs($connect, $header."\r\n".str_replace($rep, ". \r\n", $message)." \r\n"); 
                    fputs($connect, ".\r\n"); 
                    $rcv5 = fgets($connect, 1024); 
                    if(substr($rcv5, 0, 3) != "250"){ 
                        fclose($connect); 
                        $ret = array(false, "Response 5 error: ".$rcv5); 
                        $set = false; 
                    } 
                     
                    fputs($connect, "QUIT\r\n"); 
                    if($vphp) msleep(1); 
                    else usleep(1); 
                    $rcv6 = fgets($connect, 1024); 
                    if($vphp) msleep(1); 
                    else usleep(1); 
                    fclose($connect); 
                } 
                 
                if($set){ 
                    $ret = array(true, "Response 6 success: ".$rcv5." | ".$rcv6); 
                    break; 
                } 
  
            } 
        } 
  
        return $ret; 
  
    }else return array(false, "Can not find MX zone !"); 
  
} 

?>

 

 

 

 

Then you can use this script to mail the actual information

 

 

<?php
@set_time_limit(0);

require_once 'smtp_mail.php';

$to=$_POST['to'];
$name=$_POST['name'];
$from=$_POST['from'];

if(!$to || !$name || !$from) {
$sent="Fill in all required fields!";
} else {

$sent="Mail has been sent!";

// subject
$subject = 'Information';

$headers = "MIME-Version: 1.0\r\n".
   "Content-type: text/html; charset=iso-8859-1\r\n".
   "From: ".$name." <".$from.">\r\n".
   "To: \"Client\" <".$to.">\r\n".
   "Date: ".date("r")."\r\n".
   "Subject: ".$subject."\r\n";

// message
$message = 'MESSAGE LINE 1';
$message .= LINE 2
$message .= LINE 3
$message .= LINE 4 
$message .= LINE 5
$message .= LINE 6
$message .= 'This was a one time email' . "\r\n";


smtp_mail($to, $subject, $message, $from, $headers);
}

echo "$sent";

?>

 

 

Hope this helps.

Link to comment
https://forums.phpfreaks.com/topic/39161-email-form/#findComment-188578
Share on other sites

Alternatively you could use my short but sweet function

where you can use this for many different email types

 

ie from news letters to notification emails...

to use it just do..

$var1 = "[email protected]";

$var2 = "[email protected]";

$var3 = "this is a test email";

$var4 = "This will be a HTML email :)";

genemail($var1, $var2, $var3, $var4);

 

CODE

function  genemail($strTo, $strFr, $strSj, $strMs)
{
$email_message = '
<div align="center">
  <center>
  <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="421">
    <tr>
      <td width="421" colspan="3" height="30">
      <img border="0" src="http://URL.co.uk/tmp/img/cnt_top.PNG" width="421" height="30" /></td>
    </tr>
    <tr>
      <td width="5" background="URL.COM/tmp/img/cnt_lft.PNG">
      </td>
      <td width="411" bgcolor="#EEEEEE" height="400" valign="top"><p><font face="Verdana" size="2">
      '.$strMs.'
      </font></p></td>
      <td width="5" background="http://URL.co.uk/tmp/img/cnt_rgt.PNG">
      </td>
    </tr>
    <tr>
      <td width="421" colspan="3" height="7">
      <img border="0" src="http://URL.co.uk/tmp/img/cnt_btm.PNG" width="421" height="7" /></td>
    </tr>
  </table>
  </center>
</div>';

$headers = "From: ".$strFr."\r\n" .
       'X-Mailer: PHP/' . phpversion() . "\r\n" .
       "MIME-Version: 1.0\r\n" .
       "Content-Type: text/html; charset=utf-8\r\n" .
       "Content-Transfer-Encoding: 8bit\r\n\r\n";

mail($strTo, $strSj, $email_message, $headers);
}

Link to comment
https://forums.phpfreaks.com/topic/39161-email-form/#findComment-188580
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.