Skip to content

Instantly share code, notes, and snippets.

@matatabi
Created March 7, 2011 18:08
Show Gist options
  • Save matatabi/858901 to your computer and use it in GitHub Desktop.
Save matatabi/858901 to your computer and use it in GitHub Desktop.
modx で sendmail 使わずに google apps に smtp する方法
/* SMTP variables を設定
http://forum.whmcs.com/showthread.php?t=13845
↑の設定のほぼパクリ。ただ、もとネタのように、 "tls://" を tls のトリガーに使ってしまうと、コロンのせいで explode されてしまう。(e.g. "smtp1.example.com:25;smtp2.example.com")のフォーマットに対応するため。。。
なので、 tls// のみをトリガーにする。後の strpos 部分と一致してれば、トリガーは何の文字列でもOK。
*/
/////////////////////////////////////////////////
// SMTP VARIABLES
/////////////////////////////////////////////////
var $Host = "tls//smtp.gmail.com"; // the "tls//" is used later to trigger tls
var $Port = 587;
var $Helo = "";
var $SMTPAuth = true;
var $Username = "something@somedomain.com";
var $Password = "abc";
/*...
.. */
var $SMTPDebug = true;
$port = $this->Port;
}
/* Start of change */
$strpos = strpos($host,"tls//");
if($strpos !== false) {
$tls = true;
$host = str_replace("tls//","",$host);
} else {
$tls = false;
}
/* END of change */
..
else
$this->smtp->Hello($this->ServerHostname());
/* START */
if($tls == true) {
if(!$this->smtp->StartTLS()) {
$this->SetError($this->Lang("tls"));
$this->smtp->Reset();
$connection = false;
}
$this->smtp->Hello($hello);
}
/* END */
echo "SMTP -> FROM SERVER:" . $this->CRLF . $announce;
}
return true;
}
/* ....... START */
/* Initiate a TSL communication with the server.
*
* SMTP CODE 220 Ready to start TLS
* SMTP CODE 501 Syntax error (no parameters allowed)
* SMTP CODE 454 TLS not available due to temporary reason
* @access public
* @return bool success
*/
public function StartTLS() {
$this->error = null; # to avoid confusion
if(!$this->connected()) {
$this->error = array("error" => "Called StartTLS() without being connected");
return false;
}
fputs($this->smtp_conn,"STARTTLS" . $extra . $this->CRLF);
$rply = $this->get_lines();
$code = substr($rply,0,3);
if($this->do_debug >= 2) {
echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
}
if($code != 220) {
$this->error =
array("error" => "STARTTLS not accepted from server",
"smtp_code" => $code,
"smtp_msg" => substr($rply,4));
if($this->do_debug >= 1) {
echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF;
}
return false;
}
//Begin encrypted connection
if(!stream_socket_enable_crypto($this->smtp_conn, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) {
return false;
}
return true;
}
/* change all $mail->IsMail(); to $mail->IsSMTP(); */
$mail->IsSMTP();
$mail->From = $from;
$mail->FromName = $fromname;
$mail->Subject = $subject;
/* Following can be specified but not necessary
$mail->Host = "smtp.gmail.com";
$mail->SMTPAuth = true;
$mail->SMTPSecure= "ssl";
$mail->Port = 587;
$mail->Username = "something@somedomain.com";
$mail->Password = "abc";
*/
Just the usual eform stuff
[!eForm? &formid=`ContactForm` &subject=`問い合わせがありました&[+subject+]` &to=`admin@first-wood.jp` &tpl=`ContactForm` &report=`ContactFormReport` &invalidClass=`invalidValue` &automessage=`ContactFormReply` &requiredClass=`requiredValue` &cssStyle=`ContactStyles` &gotoid=`26` !]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment