Jump to content

Form to Mail


jalen

Recommended Posts

<form action="/cgi/formmail" method = "POST">

 

No idea what you mean!

if I put the code as my host suggest to use their formmail built in, how can i run other program that gets call with the action = whatever program.

 

$mail->AddAddress("John@doe.com", "John Doe");

$mail->AddAddress("Jane@doe.com", "Jane Doe");

 

 

subject, same idea

$mail->Subject    = "PHPMailer Test Subject via smtp (Gmail), basic";

their built in program doesn't allow me to do this:

 

I have yet to download phpmailer and follow your method, I will do so soon.

Link to comment
Share on other sites

  • Replies 78
  • Created
  • Last Reply

Top Posters In This Topic

I have downloaded the phpmailer and do as it says:

 

Copy class.phpmailer.php into your php.ini include_path.

If you are using the SMTP mailer then place class.smtp.php in your path as well.

 

save these two files in my same directory as my PHP ini file and change this in php ini

 

; UNIX: "/path1:/path2"

;include_path = ".:/php/includes"

;

; Windows: "\path1;\path2"

;include_path = ".;c:\php\includes"

include_path = ".;C:\Program Files\PHP\phpMailer_v2.3\class.phpmailer.php"

include_path = ".;C:\Program Files\PHP\phpMailer_v2.3\class.smtp.php"

 

After doing all this it still doesn't work.  Any ideas?

 

I always get the same error message:

 

Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\Apache\htdocs\FormToEmail.php on line 197

Link to comment
Share on other sites

What! change your php.ini back,

 

create a file called test.php, and put the code from this post, inside it, put the phpmailer classes in the same folder, and run test.php

 

from that point it should be sending emails, after that, just create a form to pass what you want to the test.php

Link to comment
Share on other sites

I did as you say, with both gmail (i just created a new email) and yahoo (made a few changes on your php file)  and save the class.phpmailer php file in the same directory as your php file and it didn't work.  It is a blank screen on the test.php browser and nothing is send to my email.

 

any ideas?

Link to comment
Share on other sites

I did as you say, with both gmail (i just created a new email) and yahoo (made a few changes on your php file) 

You don't need to make any changes to the php.ini file,

 

and save the class.phpmailer php file in the same directory as your php file and it didn't work.  It is a blank screen on the test.php browser and nothing is send to my email.

 

any ideas?

You did something wrong, if you did it correctly your get either

 

Mailer Error:

or

Message sent!
Link to comment
Share on other sites

hi MadTechie

 

Let me go over what I did,

 

I created a gmail account testtst797@gmail.com, copied your code and adjust a few things

as you could see on the bottom.

 

<?php
require_once('../class.phpmailer.php');
$mail             = new PHPMailer();
$body             = "testing <b>PHP Mailer</b> wooohooo";

$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
                                           // 1 = errors and messages
                                           // 2 = messages only
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
$mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
$mail->Port       = 465;                   // set the SMTP port for the GMAIL server

//update
$mail->Username   = "testtst797@gmail.com";  // GMAIL username
$mail->Password   = "ABC2873";            // GMAIL password
$mail->SetFrom('testtst797@gmail.com', 'First Last');


$mail->Subject    = "PHPMailer Test Subject via smtp (Gmail), basic";

$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test

$mail->MsgHTML($body);

$address = "whoto@otherdomain.com";
$mail->AddAddress($address, "John Doe");

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

 

copied class.phpmailer and save it in the same directory as I save your code which is TEST.php

 

I then just go to browser and type http://localhost/test.php

 

it shows nothing, blank page all white.  mail didn't get sent

 

any suggestions?

Link to comment
Share on other sites

<?php

error_reporting(E_ALL);
require_once('class.phpmailer.php');

//require_once('../class.phpmailer.php');
$mail             = new PHPMailer();
$body             = "testing <b>PHP Mailer</b> wooohooo";

$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
                                           // 1 = errors and messages
                                           // 2 = messages only
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
$mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
$mail->Port       = 465;                   // set the SMTP port for the GMAIL server

//update
$mail->Username   = "testtst797@gmail.com";  // GMAIL username
$mail->Password   = "abc87645";            // GMAIL password
$mail->SetFrom('testtst797@gmail.com', 'First Last');


$mail->Subject    = "PHPMailer Test Subject via smtp (Gmail), basic";

$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test

$mail->MsgHTML($body);

$address = "whoto@otherdomain.com";
$mail->AddAddress($address, "John Doe");

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

Link to comment
Share on other sites

This is the code i just ran and it works fine

 

<?php
//MyEmail eg myemail@gmail.com
//MyPassword eg mypassword
error_reporting(E_ALL);
require_once('class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded

$mail             = new PHPMailer();
$body             = "testing <b>PHP Mailer</b> wooohooo";

$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
                                           // 1 = errors and messages
                                           // 2 = messages only
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
$mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
$mail->Port       = 465;                   // set the SMTP port for the GMAIL server
$mail->Username   = "MyEmail";  // GMAIL username
$mail->Password   = "My Password";            // GMAIL password

$mail->SetFrom('MyEmail', 'First Last');

$mail->AddReplyTo('MyEmail', 'First Last');

$mail->Subject    = "PHPMailer Test Subject via smtp (Gmail), basic";

$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test

$mail->MsgHTML($body);

$address = "MyEmail";
$mail->AddAddress($address, "John Doe");

#$mail->AddAttachment("images/phpmailer.gif");      // attachment

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

 

you should be getting an error at the very least!

 

Example Output

SMTP -> FROM SERVER:220 mx.google.com ESMTP d4sm512560fga.16

SMTP -> FROM SERVER: 250-mx.google.com at your service, [02.174.120.65] 250-SIZE 35651584 250-8BITMIME 250-AUTH LOGIN PLAIN 250-ENHANCEDSTATUSCODES 250 PIPELINING

SMTP -> FROM SERVER:250 2.1.0 OK d4sm561560fgb.16

SMTP -> FROM SERVER:250 2.1.5 OK d4sm561560fgb.16

SMTP -> FROM SERVER:354 Go ahead d4sm561560fgb.16

SMTP -> FROM SERVER:250 2.0.0 OK 1244373868 d4sm561560fgb.16

Message sent!

Link to comment
Share on other sites

I copied the exact code you just had and made only Changes to myemail and my password and run it in localhost/TEST.php and again is blank. 

 

my php ini file is this:  I didn't change anything

 

[mail function]

; For Win32 only.

SMTP = localhost

smtp_port = 25

 

;;;;;;;;;;;;;;;;;;;;;;;;;

; Paths and Directories ;

;;;;;;;;;;;;;;;;;;;;;;;;;

 

; UNIX: "/path1:/path2"

;include_path = ".:/php/includes"

;

; Windows: "\path1;\path2"

;include_path = ".;c:\php\includes"

 

Link to comment
Share on other sites

;;;;;;;;;;;;;;;;;;;;;;;;;

; Paths and Directories ;

;;;;;;;;;;;;;;;;;;;;;;;;;

 

; UNIX: "/path1:/path2"

;include_path = ".:/php/includes"

;

; Windows: "\path1;\path2"

;include_path = ".;c:\php\includes"

 

Php ini is this, doesn't look like anything is changed.

Link to comment
Share on other sites

If its not including files i'm not too sure,

maybe try adding this

ini_set('include_path',".");

at the start!

 

personally if your not getting any errors even with

error_reporting(E_ALL);

then your need to check the logs or something as your giving me nothing to work with!

Link to comment
Share on other sites

this code on the bottom I uploaded to my hosting site, and uploaded my php ini files and it work, the mailing went through. 

The only thing is that on my local host it doesn't work,

 

and when I put this, it gives me an error message

 

error_reporting(E_ALL);

 

 

Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\Apache\htdocs\FormToEmail.php on line 197

failed

 

so i don't know why your code gives nothing, a blank page, if you think is the ini file, then show me how to use your ini file then or what suggestion do you have?

 

<form action="FormToEmail.php" method="post">
<table border="1" bgcolor="yellow" cellspacing="5">
<tr><td>Email address</td><td><input type="text" size="30" name="my_email"></td></tr>
<tr><td>Name</td><td><input type="text" size="30" name="name"></td></tr>
<tr><td>Email address</td><td><input type="text" size="30" name="email"></td></tr>
<tr><td valign="top">Comments</td><td><textarea name="comments" rows="6" cols="30"></textarea></td></tr>
<tr><td> </td><td><input type="submit" value="Send"></td></tr>
</table>
</form>


<?php


$my_email = "myemail";





$errors = array();



if(count($_COOKIE)){foreach(array_keys($_COOKIE) as $value){unset($_REQUEST[$value]);}}



function recursive_array_check_header($element_value)
{

global $set;

if(!is_array($element_value)){if(preg_match("/(%0A|%0D|\n+|\r+)(content-type:|to:|cc:|bcc:)/i",$element_value)){$set = 1;}}
else
{

foreach($element_value as $value){if($set){break;} recursive_array_check_header($value);}

}

}

recursive_array_check_header($_REQUEST);

if($set){$errors[] = "You cannot send an email header";}

unset($set);


if(isset($_REQUEST['email']) && !empty($_REQUEST['email']))
{

if(preg_match("/(%0A|%0D|\n+|\r+|:)/i",$_REQUEST['email'])){$errors[] = "Email address may not contain a new line or a colon";}

$_REQUEST['email'] = trim($_REQUEST['email']);

if(substr_count($_REQUEST['email'],"@") != 1 || stristr($_REQUEST['email']," ")){$errors[] = "Email address is invalid";}else{$exploded_email = explode("@",$_REQUEST['email']);if(empty($exploded_email[0]) || strlen($exploded_email[0]) > 64 || empty($exploded_email[1])){$errors[] = "Email address is invalid";}else{if(substr_count($exploded_email[1],".") == 0){$errors[] = "Email address is invalid";}else{$exploded_domain = explode(".",$exploded_email[1]);if(in_array("",$exploded_domain)){$errors[] = "Email address is invalid";}else{foreach($exploded_domain as $value){if(strlen($value) > 63 || !preg_match('/^[a-z0-9-]+$/i',$value)){$errors[] = "Email address is invalid"; break;}}}}}}

}



if(!(isset($_SERVER['HTTP_REFERER']) && !empty($_SERVER['HTTP_REFERER']) && stristr($_SERVER['HTTP_REFERER'],$_SERVER['HTTP_HOST']))){$errors[] = "You must enable referrer logging to use the form";}



function recursive_array_check_blank($element_value)
{

global $set;

if(!is_array($element_value)){if(!empty($element_value)){$set = 1;}}
else
{

foreach($element_value as $value){if($set){break;} recursive_array_check_blank($value);}

}

}

recursive_array_check_blank($_REQUEST);

if(!$set){$errors[] = "You cannot send a blank form";}

unset($set);



if(count($errors)){foreach($errors as $value){print "$value<br>";} exit;}

if(!defined("PHP_EOL")){define("PHP_EOL", strtoupper(substr(PHP_OS,0,3) == "WIN") ? "\r\n" : "\n");}



function build_message($request_input){if(!isset($message_output)){$message_output ="";}if(!is_array($request_input)){$message_output = $request_input;}else{foreach($request_input as $key => $value){if(!empty($value)){if(!is_numeric($key)){$message_output .= str_replace("_"," ",ucfirst($key)).": ".build_message($value).PHP_EOL.PHP_EOL;}else{$message_output .= build_message($value).", ";}}}}return rtrim($message_output,", ");}

$message = build_message($_REQUEST);


$message = stripslashes($message);

$subject = "FormToEmail Comments";

$headers = "From: " . $_REQUEST['email'];

mail($my_email,$subject,$message,$headers);

?>


<html>

<head>
</head>

<body bgcolor="yellow" text="#000000">

<div>
<center>
<b>Thank you <?php print stripslashes($_REQUEST['name']); ?></b>
<br>Your message has been sent
</center>
</div>

</body>
</html>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • 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.