char *tempMailTo;
char *tsm_errmsg = NULL;
ADDRESS *addr;
- char *bufferTo = NULL, *bufferCc = NULL, *bufferBcc = NULL;
- int offset;
-
+ char *bufferTo = NULL, *bufferCc = NULL, *bufferBcc = NULL, *bufferHeader = NULL;
+ int offset, bufferLen = 0;;
+
+ if (headers)
+ bufferLen += strlen(headers);
+ if (to)
+ bufferLen += strlen(to) + 6;
+ if (cc)
+ bufferLen += strlen(cc) + 6;
+
+ bufferHeader = (char *)emalloc(bufferLen);
+ memset(bufferHeader, 0, bufferLen);
if (to && *to) {
+ strcat(bufferHeader, "To: ");
+ strcat(bufferHeader, to);
+ strcat(bufferHeader, "\r\n");
tempMailTo = estrdup(to);
bufferTo = (char *)emalloc(strlen(to));
offset = 0;
}
if (cc && *cc) {
+ strcat(bufferHeader, "Cc: ");
+ strcat(bufferHeader, cc);
+ strcat(bufferHeader, "\r\n");
tempMailTo = estrdup(cc);
bufferCc = (char *)emalloc(strlen(cc));
offset = 0;
}
}
+ strcat(bufferHeader, headers);
- if (TSendMail(INI_STR("SMTP"), &tsm_err, &tsm_errmsg, headers, subject, bufferTo, message, bufferCc, bufferBcc, rpath) != SUCCESS) {
+ if (TSendMail(INI_STR("SMTP"), &tsm_err, &tsm_errmsg, bufferHeader, subject, bufferTo, message, bufferCc, bufferBcc, rpath) != SUCCESS) {
if (tsm_errmsg) {
php_error(E_WARNING, "%s(): %s", get_active_function_name(TSRMLS_C), tsm_errmsg);
efree(tsm_errmsg);
if (bufferBcc) {
efree(bufferBcc);
}
+ if (bufferHeader) {
+ efree(bufferHeader);
+ }
#else
if (!INI_STR("sendmail_path")) {
return 0;
}
efree(tempMailTo);
+ if (mailCc && *mailCc) {
+ tempMailTo = estrdup(mailCc);
+ /* Send mail to all rcpt's */
+ token = strtok(tempMailTo, ",");
+ while(token != NULL)
+ {
+ snprintf(Buffer, MAIL_BUFFER_SIZE, "RCPT TO:<%s>\r\n", token);
+ if ((res = Post(Buffer)) != SUCCESS) {
+ efree(tempMailTo);
+ return (res);
+ }
+ if ((res = Ack(&server_response)) != SUCCESS) {
+ SMTP_ERROR_RESPONSE(server_response);
+ efree(tempMailTo);
+ return (res);
+ }
+ token = strtok(NULL, ",");
+ }
+ efree(tempMailTo);
+ }
/* Send mail to all Cc rcpt's */
- if (headers && (pos1 = strstr(headers_lc, "cc:"))) {
+ else if (headers && (pos1 = strstr(headers_lc, "cc:"))) {
/* Real offset is memaddress from the original headers + difference of
* string found in the lowercase headrs + 3 characters to jump over
* the cc: */
efree(tempMailTo);
}
- if (mailCc && *mailCc) {
- tempMailTo = estrdup(mailCc);
+ /* Send mail to all Bcc rcpt's
+ This is basically a rip of the Cc code above.
+ Just don't forget to remove the Bcc: from the header afterwards. */
+ if (mailBcc && *mailBcc) {
+ tempMailTo = estrdup(mailBcc);
/* Send mail to all rcpt's */
token = strtok(tempMailTo, ",");
while(token != NULL)
}
efree(tempMailTo);
}
-
- /* Send mail to all Bcc rcpt's
- This is basically a rip of the Cc code above.
- Just don't forget to remove the Bcc: from the header afterwards. */
- if (headers) {
+ else if (headers) {
if (pos1 = strstr(headers_lc, "bcc:")) {
/* Real offset is memaddress from the original headers + difference of
* string found in the lowercase headrs + 4 characters to jump over
}
}
- if (mailBcc && *mailBcc) {
- tempMailTo = estrdup(mailBcc);
- /* Send mail to all rcpt's */
- token = strtok(tempMailTo, ",");
- while(token != NULL)
- {
- snprintf(Buffer, MAIL_BUFFER_SIZE, "RCPT TO:<%s>\r\n", token);
- if ((res = Post(Buffer)) != SUCCESS) {
- efree(tempMailTo);
- return (res);
- }
- if ((res = Ack(&server_response)) != SUCCESS) {
- SMTP_ERROR_RESPONSE(server_response);
- efree(tempMailTo);
- return (res);
- }
- token = strtok(NULL, ",");
- }
- efree(tempMailTo);
- }
-
if ((res = Post("DATA\r\n")) != SUCCESS) {
efree(stripped_header);
return (res);