Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once "Mail.php";
- /* This is a PHP script to handle form-mailing on Webfaction hosted accounts.
- *
- * Normal PHP mail scripts won't work due to the way Webfaction has their stuff set up,
- * so this is a pretty decent workaround. It's a combination of various other efforts
- * by different people who use Webfaction; if you feel you're not being credited for any
- * of the effort/code below, feel free to email/message me on Github. I just want this to
- * be easily search-able, so I've thrown it here.
- *
- * Email me: ryan [at] venodesigns.net
- */
- function smtp($to, $subject, $message, $additional_headers = "") {
- /* STMP Server Settings */
- $smtp_server = "smtp.webfaction.com";
- $smtp_username = "remaxbravo_contactforms";
- $smtp_password = "5255053678979";
- $smtp_default_from = "contact@fredva.com";
- $to = (string) $to;
- $subject = (string) $subject;
- $message = (string) $message;
- $additional_headers = (string) $additional_headers;
- /* Pear expects an Array */
- $raw_headers = str_replace("\r", "", $raw_headers);
- $raw_headers = explode("\n", $additional_headers);
- $headers = Array("To" => $to, "Subject" => $subject);
- $recipients = $to;
- foreach($raw_headers as $raw_header) {
- $header = explode(":", $raw_header, 2);
- if (count($header) != 2)
- continue; /* Silently kill offending headers. */
- $header_key = ucfirst(trim($header[0]));
- $header_value = trim($header[1]);
- if ($header_key == "To" || $header_key == "Subject")
- continue;
- if($header_key == "Cc" || $header_key == "Bcc")
- $recipients .= ", " . $header_value;
- $headers[$header_key] = $header_value;
- }
- /* Set a default "From" header if none was provided */
- if (!array_key_exists("From", $headers))
- $headers["From"] = $smtp_default_from;
- /* Create the SMTP object and send mail. Must return true on success,
- * false on failure.
- */
- $smtp = Mail::factory("smtp",
- Array("host" => $smtp_server,
- "auth" => true,
- "username" => $smtp_username,
- "password" => $smtp_password
- )
- );
- $result = $smtp->send($recipients, $headers, $message);
- if (PEAR::IsError($result)) {
- /*echo $result->getMessage(); -- Uncomment if you want some debugging */
- return false;
- } else {
- return true;
- }
- }
- /* Grab your desired parameters from the $_REQUEST object.
- * Anything other than name/email needs to be concatenated into the final message.
- */
- $clientName = $_REQUEST["name"];
- $clientEmail = $_REQUEST["email"];
- $clientPhone = $_REQUEST["phone"];
- $projectInfo = $_REQUEST["projectinfo"];
- /* Said concatenation efforts described above. */
- $finalProject = "Name: " . $clientName . "\nEmail: " . $clientEmail . "\nPhone Number: " . $clientPhone . "\nProject Info: " . $projectInfo;
- /* A generic callback message that we'll throw to the user so they know we got their message. */
- $callbackMessage = "Thanks! Got your message, will reply shortly.";
- /* This is totally optional, depending on what you wanna do... basically, everything that we pulled out of the request object
- * above is a REQUIRED field, so we check to make sure it didn't come back as something bogus. This (along with the stuff from $_REQUEST above)
- * can obviously change, depending on your needs.
- */
- if(!isset($_GET["name"]) || !isset($_GET["email"]) || !isset($_GET["phone"]) || !isset($_GET["projectinfo"])) {
- header('Location:/contact/mcgrath/?error=true');
- }
- /* Fairly self explanatory... send the client the email saying that we got their message, then send ourselves the message. Ideally, you should reverse this,
- * but I'm feeling kind of lazy at the moment. ;P
- */
- smtp($clientEmail, "Thank you!", $callbackMessage, "");
- smtp("kmcgrath@remax.net", "Contact: " . $clientName, $finalProject, "");
- /* Redirect to an arbitrary location after we send that junx. */
- header('Location:/thanks/');
- ?>
Add Comment
Please, Sign In to add comment